public void sendEvent(String connectionId, String eventBody, Handler<AsyncResult<Void>> handler) { System.out.printf("moduleConnectionIdEventPut called for %s%n", connectionId); System.out.println(eventBody); this.sendEventHelper(connectionId, new Message(eventBody), handler); }
Message msg = new Message(this.getBody()); msg.setProperty(propertyName, propertyValue); msg.setMessageId(this.systemProperties.get(MESSAGE_ID_KEY)); msg.setProperty(HTTPS_APP_PROPERTY_PREFIX + USER_ID_KEY, this.systemProperties.get(USER_ID_KEY)); msg.setCorrelationId(this.systemProperties.get(CORRELATION_ID_KEY)); msg.setContentType(this.systemProperties.get(CONTENT_TYPE_KEY)); msg.setContentEncoding(this.systemProperties.get(CONTENT_ENCODING_KEY)); msg.setProperty(HTTPS_APP_PROPERTY_PREFIX + TO_KEY, this.systemProperties.get(TO_KEY));
byte[] msgBody = message.getBytes(); httpsMsg.body = Arrays.copyOf(msgBody, msgBody.length); MessageProperty[] msgProperties = message.getProperties(); httpsMsg.properties = new MessageProperty[msgProperties.length]; int countProperty; if (message.getUserId() != null) sysProperties.put(USER_ID_KEY, message.getUserId()); if (message.getMessageId() != null) sysProperties.put(MESSAGE_ID_KEY, message.getMessageId()); if (message.getCorrelationId() != null) sysProperties.put(CORRELATION_ID_KEY, message.getCorrelationId()); if (message.getTo() != null) sysProperties.put(TO_KEY, message.getTo()); if (message.getContentEncoding() != null) sysProperties.put(CONTENT_ENCODING_KEY, message.getContentEncoding()); if (message.getContentType() != null)
private static boolean hasExpectedSystemProperties(Message msg) { if (msg.getCorrelationId() == null || !msg.getCorrelationId().equals(expectedCorrelationId)) { return false; } if (msg.getMessageId() == null || !msg.getMessageId().equals(expectedMessageId)) { return false; } //all system properties are as expected return true; }
public static Message createMessageWithErrorInjectionProperties(String faultType, String reason, int delayInSecs, int durationInSecs) { String dataBuffer = UUID.randomUUID().toString(); Message message = new Message(dataBuffer); message.setProperty("AzIoTHub_FaultOperationType", faultType); message.setProperty("AzIoTHub_FaultOperationCloseReason", reason); message.setProperty("AzIoTHub_FaultOperationDelayInSecs", String.valueOf(delayInSecs)); message.setProperty("AzIoTHub_FaultOperationDurationInSecs", String.valueOf(durationInSecs)); return message; } }
/** * Constructor. * @param body The body of the new Message instance. It is internally serialized to a byte array using UTF-8 encoding. */ public Message(String body) { if (body == null) { throw new IllegalArgumentException("Message body cannot be 'null'."); } initialize(); this.body = body.getBytes(DEFAULT_IOTHUB_MESSAGE_CHARSET); this.setContentType(DEFAULT_IOTHUB_MESSAGE_CHARSET.name()); }
Message msg = new Message(msgStr); msg.setContentType("application/json"); msg.setProperty("temperatureAlert", temperature > 28 ? "true" : "false"); msg.setMessageId(java.util.UUID.randomUUID().toString()); msg.setExpiryTime(D2C_MESSAGE_TIMEOUT); System.out.println(msgStr);
if (message == null || message.getBytes() == null) separatorNeeded = appendPropertyIfPresent(stringBuilder, separatorNeeded, MESSAGE_ID, message.getMessageId()); separatorNeeded = appendPropertyIfPresent(stringBuilder, separatorNeeded, CORRELATION_ID, message.getCorrelationId()); separatorNeeded = appendPropertyIfPresent(stringBuilder, separatorNeeded, USER_ID, message.getUserId()); separatorNeeded = appendPropertyIfPresent(stringBuilder, separatorNeeded, TO, message.getTo()); separatorNeeded = appendPropertyIfPresent(stringBuilder, separatorNeeded, OUTPUT_NAME, message.getOutputName()); separatorNeeded = appendPropertyIfPresent(stringBuilder, separatorNeeded, CONNECTION_DEVICE_ID, message.getConnectionDeviceId()); separatorNeeded = appendPropertyIfPresent(stringBuilder, separatorNeeded, CONNECTION_MODULE_ID, message.getConnectionModuleId()); separatorNeeded = appendPropertyIfPresent(stringBuilder, separatorNeeded, CONTENT_ENCODING, message.getContentEncoding()); separatorNeeded = appendPropertyIfPresent(stringBuilder, separatorNeeded, CONTENT_TYPE, message.getContentType()); for (MessageProperty property : message.getProperties())
message.setMessageId(value); break; case IOTHUB_ACK: message.setCorrelationId(value); break; case USER_ID: message.setOutputName(value); break; case CONTENT_ENCODING: message.setContentEncoding(value); break; case CONTENT_TYPE: message.setContentType(value); break; case ABSOLUTE_EXPIRY_TIME: message.setProperty(key, value);
if (message.getMessageId() != null) properties.setMessageId(message.getMessageId()); if (message.getCorrelationId() != null) properties.setCorrelationId(message.getCorrelationId()); if (message.getContentType() != null) properties.setContentType(Symbol.valueOf(message.getContentType())); if (message.getContentEncoding() != null) properties.setContentEncoding(Symbol.valueOf(message.getContentEncoding())); if (message.getProperties().length > 0) for(MessageProperty messageProperty : message.getProperties()) if (message.getConnectionDeviceId() != null) userProperties.put(MessageProperty.CONNECTION_DEVICE_ID, message.getConnectionDeviceId()); if (message.getConnectionModuleId() != null) userProperties.put(MessageProperty.CONNECTION_MODULE_ID, message.getConnectionModuleId()); Binary binary = new Binary(message.getBytes());
public IotHubMessageResult execute(com.microsoft.azure.sdk.iot.device.Message msg, Object context) { messageIdListStoredOnReceive.add(msg.getMessageId()); // add received messsage id to messageList return IotHubMessageResult.COMPLETE; } }
public IotHubMessageResult execute(Message msg, Object context) { Counter counter = (Counter) context; System.out.println( "Received message " + counter.toString() + " with content: " + new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET)); for (MessageProperty messageProperty : msg.getProperties()) { System.out.println(messageProperty.getName() + " : " + messageProperty.getValue()); } counter.increment(); return IotHubMessageResult.COMPLETE; } }
if (message.getContentEncoding() != null) request.setHeaderField(MessageProperty.IOTHUB_CONTENT_ENCODING, message.getContentEncoding()); if (message.getContentType() != null) request.setHeaderField(MessageProperty.IOTHUB_CONTENT_TYPE, message.getContentType()); IotHubTransportMessage transportMessage = new IotHubTransportMessage(message.getBytes(), message.getMessageType(), message.getMessageId(), message.getCorrelationId(), message.getProperties()); if (status == IotHubStatusCode.OK || status == IotHubStatusCode.OK_EMPTY)
transportMessage = new IotHubTransportMessage(message.getBytes(), message.getMessageType(), message.getMessageId(), message.getCorrelationId(), message.getProperties()); transportMessage.setIotHubConnectionString(message.getIotHubConnectionString());
transportMessage = new IotHubTransportMessage(message.getBytes(), message.getMessageType(), message.getMessageId(), message.getCorrelationId(), message.getProperties()); transportMessage.setMessageCallback(this.config.getDeviceTelemetryMessageCallback(message.getInputName())); transportMessage.setMessageCallbackContext(this.config.getDeviceTelemetryMessageContext(message.getInputName()));
public void sendOutputEvent(String connectionId, String outputName, String eventBody, Handler<AsyncResult<Void>> handler) { System.out.printf("sendOutputEvent called for %s, %s%n", connectionId, outputName); System.out.println(eventBody); Message msg = new Message(eventBody); msg.setOutputName(outputName); this.sendEventHelper(connectionId, msg, handler); }
messagesToSend.get(i).message.setExpiryTime(200);
public IotHubMessageResult execute(Message msg, Object context) { Counter counter = (Counter) context; System.out.println( "Device Client " + msg.getIotHubConnectionString().getDeviceId() + " received message " + counter.toString() + " with content: " + new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET)); for (MessageProperty messageProperty : msg.getProperties()) { System.out.println(messageProperty.getName() + " : " + messageProperty.getValue()); } IotHubMessageResult res = IotHubMessageResult.COMPLETE; System.out.println( "Responding to message " + counter.toString() + " with " + res.name()); counter.increment(); return res; } }
Message expiredMessage = new Message("This message has expired"); expiredMessage.setAbsoluteExpiryTime(1); //setting this to 0 causes the message to never expire Success messageSentExpiredCallback = new Success();
public synchronized IotHubMessageResult execute(Message msg, Object context) { System.out.println("MessageCallback called"); this._client.setMessageCallback(this._inputName, null, null); String result = new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET); System.out.printf("result = %s%n", result); try { if (this._handler != null) { this._handler.handle(Future.succeededFuture(result)); } } catch (Exception e) { System.out.printf("Ignoring exception %s%n", e.toString()); } return IotHubMessageResult.COMPLETE; } }