當前位置: 首頁>>代碼示例>>Java>>正文


Java Message.getBytes方法代碼示例

本文整理匯總了Java中com.microsoft.azure.iothub.Message.getBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.getBytes方法的具體用法?Java Message.getBytes怎麽用?Java Message.getBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.microsoft.azure.iothub.Message的用法示例。


在下文中一共展示了Message.getBytes方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseHttpsMessage

import com.microsoft.azure.iothub.Message; //導入方法依賴的package包/類
/**
 * Returns the HTTPS message represented by the service-bound message.
 *
 * @param message the service-bound message to be mapped to its HTTPS message
 * equivalent.
 *
 * @return the HTTPS message represented by the service-bound message.
 */
public static HttpsSingleMessage parseHttpsMessage(Message message) {
    HttpsSingleMessage httpsMsg = new HttpsSingleMessage();

    // Codes_SRS_HTTPSSINGLEMESSAGE_11_001: [The parsed HttpsSingleMessage shall have a copy of the original message body as its body.]
    byte[] msgBody = message.getBytes();
    httpsMsg.body = Arrays.copyOf(msgBody, msgBody.length);

    // Codes_SRS_HTTPSSINGLEMESSAGE_11_003: [The parsed HttpsSingleMessage shall add the prefix 'iothub-app-' to each of the message properties.]
    MessageProperty[] msgProperties = message.getProperties();
    httpsMsg.properties = new MessageProperty[msgProperties.length];
    for (int i = 0; i < msgProperties.length; ++i)
    {
        MessageProperty property = msgProperties[i];

        httpsMsg.properties[i] = new MessageProperty(
                HTTPS_APP_PROPERTY_PREFIX + property.getName(),
                property.getValue());
    }

    return httpsMsg;
}
 
開發者ID:Redcley,項目名稱:iot-insider-lab,代碼行數:30,代碼來源:HttpsSingleMessage.java

示例2: execute

import com.microsoft.azure.iothub.Message; //導入方法依賴的package包/類
public IotHubMessageResult execute(Message msg, Object context) {
    IotHubMessageResult result = IotHubMessageResult.REJECT;

    try {
        String commandJson = new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET);

        //DeviceCommand command = DeviceCommand.fromJSON(commandJson);
        org.json.JSONObject jsonObject = new JSONObject(commandJson);

        Log.d("IoTHubSvc", "Received message with content: " + commandJson);
        String commandName = jsonObject.getString("Name");

        if (MESSAGE_START_TELEMETRY.equalsIgnoreCase(commandName)) {
            //SendEvent.startTelemetry();
            onStartTelemetry();
            result = IotHubMessageResult.COMPLETE;
        } else if (MESSAGE_STOP_TELEMETRY.equalsIgnoreCase(commandName)) {
            //SendEvent.stopTelemetry();
            onStopTelemetry();
            result = IotHubMessageResult.COMPLETE;
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }

    return result;
}
 
開發者ID:Redcley,項目名稱:iot-insider-lab,代碼行數:28,代碼來源:IoTHubService.java

示例3: sendEvent

import com.microsoft.azure.iothub.Message; //導入方法依賴的package包/類
/**
 * Sends an event message.
 *
 * @param message the event message.
 *
 * @return the status code from sending the event message.
 *
 * @throws IllegalStateException if the MqttIotHubConnection is not open
 */
public IotHubStatusCode sendEvent(Message message) throws IllegalStateException
{
    synchronized (MQTT_CONNECTION_LOCK)
    {
        // Codes_SRS_MQTTIOTHUBCONNECTION_15_010: [If the message is null or empty,
        // the function shall return status code BAD_FORMAT.]
        if (message == null || message.getBytes() == null || message.getBytes().length == 0)
        {
            return IotHubStatusCode.BAD_FORMAT;
        }

        // Codes_SRS_MQTTIOTHUBCONNECTION_15_013: [If the MQTT connection is closed,
        // the function shall throw an IllegalStateException.]
        if (this.state == ConnectionState.CLOSED)
        {
            throw new IllegalStateException("Cannot send event using a closed MQTT connection");
        }

        // Codes_SRS_MQTTIOTHUBCONNECTION_15_008: [The function shall send an event message
        // to the IoT Hub given in the configuration.]
        // Codes_SRS_MQTTIOTHUBCONNECTION_15_009: [The function shall send the message payload.]
        // Codes_SRS_MQTTIOTHUBCONNECTION_15_011: [If the message was successfully received by the service,
        // the function shall return status code OK_EMPTY.]
        IotHubStatusCode result = IotHubStatusCode.OK_EMPTY;

        try
        {
            inFlightCount++;
            while (inFlightCount >= maxInFlightCount)
            {
                Thread.sleep(10);
            }

            MqttMessage mqttMessage = new MqttMessage(message.getBytes());
            mqttMessage.setQos(qos);

            IMqttDeliveryToken publishToken = asyncClient.publish(publishTopic, mqttMessage);

        }
        // Codes_SRS_MQTTIOTHUBCONNECTION_15_012: [If the message was not successfully
        // received by the service, the function shall return status code ERROR.]
        catch(Exception e)
        {
            result = IotHubStatusCode.ERROR;
        }

        return result;
    }
}
 
開發者ID:Redcley,項目名稱:iot-insider-lab,代碼行數:59,代碼來源:MqttIotHubConnection.java


注:本文中的com.microsoft.azure.iothub.Message.getBytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。