Search in sources :

Example 1 with Section

use of org.apache.qpid.proton.amqp.messaging.Section in project azure-iot-sdk-java by Azure.

the class AmqpsTransport method iotHubMessageToProtonMessage.

/**
     * Creates a proton message from the IoTHub message.
     * @param message the IoTHub input message.
     * @return the proton message.
     */
private MessageImpl iotHubMessageToProtonMessage(com.microsoft.azure.sdk.iot.device.Message message) {
    logger.LogInfo("Started converting IoT Hub message into AmpqsMessage, method name is %s ", logger.getMethodName());
    MessageImpl outgoingMessage = (MessageImpl) Proton.message();
    logger.LogInfo("Content of message is %s, method name is %s ", new String(message.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET), logger.getMethodName());
    Properties properties = new Properties();
    if (message.getMessageId() != null) {
        properties.setMessageId(message.getMessageId());
    }
    outgoingMessage.setProperties(properties);
    // Codes_SRS_AMQPSTRANSPORT_15_038: [The function shall add all user properties to the application properties of the Proton message.]
    if (message.getProperties().length > 0) {
        Map<String, String> userProperties = new HashMap<>(message.getProperties().length);
        for (MessageProperty messageProperty : message.getProperties()) {
            if (!MessageProperty.RESERVED_PROPERTY_NAMES.contains(messageProperty.getName())) {
                userProperties.put(messageProperty.getName(), messageProperty.getValue());
            }
        }
        ApplicationProperties applicationProperties = new ApplicationProperties(userProperties);
        outgoingMessage.setApplicationProperties(applicationProperties);
    }
    Binary binary = new Binary(message.getBytes());
    Section section = new Data(binary);
    outgoingMessage.setBody(section);
    logger.LogInfo("Started converting IoT Hub message into AmpqsMessage, method name is %s ", logger.getMethodName());
    return outgoingMessage;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) Data(org.apache.qpid.proton.amqp.messaging.Data) Binary(org.apache.qpid.proton.amqp.Binary) Properties(org.apache.qpid.proton.amqp.messaging.Properties) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) Section(org.apache.qpid.proton.amqp.messaging.Section)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Binary (org.apache.qpid.proton.amqp.Binary)1 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)1 Data (org.apache.qpid.proton.amqp.messaging.Data)1 Properties (org.apache.qpid.proton.amqp.messaging.Properties)1 Section (org.apache.qpid.proton.amqp.messaging.Section)1 MessageImpl (org.apache.qpid.proton.message.impl.MessageImpl)1