Search in sources :

Example 16 with ApplicationProperties

use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project activemq-artemis by apache.

the class AmqpMessage method lazyCreateApplicationProperties.

private void lazyCreateApplicationProperties() {
    if (applicationPropertiesMap == null) {
        applicationPropertiesMap = new HashMap<>();
        message.setApplicationProperties(new ApplicationProperties(applicationPropertiesMap));
    }
}
Also used : ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties)

Example 17 with ApplicationProperties

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

the class AmqpsMethodsSenderLinkHandler method iotHubMessageToProtonMessage.

@Override
protected MessageImpl iotHubMessageToProtonMessage(Message message) {
    if (message.getMessageType() == MessageType.DEVICE_METHODS) {
        MessageImpl protonMessage = super.iotHubMessageToProtonMessage(message);
        IotHubTransportMessage deviceMethodMessage = (IotHubTransportMessage) message;
        Properties properties;
        if (protonMessage.getProperties() != null) {
            properties = protonMessage.getProperties();
        } else {
            properties = new Properties();
        }
        if (deviceMethodMessage.getRequestId() != null) {
            properties.setCorrelationId(UUID.fromString(deviceMethodMessage.getRequestId()));
        }
        protonMessage.setProperties(properties);
        Map<String, Object> userProperties = new HashMap<>();
        if (deviceMethodMessage.getStatus() != null) {
            userProperties.put(APPLICATION_PROPERTY_KEY_IOTHUB_STATUS, Integer.parseInt(deviceMethodMessage.getStatus()));
        }
        if (protonMessage.getApplicationProperties() != null && protonMessage.getApplicationProperties().getValue() != null) {
            Map<String, Object> applicationPropertiesMap = protonMessage.getApplicationProperties().getValue();
            userProperties.putAll(applicationPropertiesMap);
        }
        ApplicationProperties applicationProperties = new ApplicationProperties(userProperties);
        protonMessage.setApplicationProperties(applicationProperties);
        return protonMessage;
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) Properties(org.apache.qpid.proton.amqp.messaging.Properties) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl)

Example 18 with ApplicationProperties

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

the class AmqpsSenderLinkHandler method iotHubMessageToProtonMessage.

MessageImpl iotHubMessageToProtonMessage(Message message) {
    log.trace("Converting IoT Hub message to proton message for {} sender link with address {} and link correlation id {}. IoT Hub message correlationId {}", getLinkInstanceType(), this.senderLinkAddress, this.linkCorrelationId, message.getCorrelationId());
    MessageImpl outgoingMessage = (MessageImpl) Proton.message();
    Properties properties = new Properties();
    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()));
    }
    outgoingMessage.setProperties(properties);
    Map<String, Object> userProperties = new HashMap<>();
    if (message.getProperties().length > 0) {
        for (MessageProperty messageProperty : message.getProperties()) {
            if (!MessageProperty.RESERVED_PROPERTY_NAMES.contains(messageProperty.getName())) {
                userProperties.put(messageProperty.getName(), messageProperty.getValue());
            }
        }
    }
    if (message.getConnectionDeviceId() != null) {
        userProperties.put(MessageProperty.CONNECTION_DEVICE_ID, message.getConnectionDeviceId());
    }
    if (message.getConnectionModuleId() != null) {
        userProperties.put(MessageProperty.CONNECTION_MODULE_ID, message.getConnectionModuleId());
    }
    if (message.getCreationTimeUTC() != null) {
        userProperties.put(MessageProperty.IOTHUB_CREATION_TIME_UTC, message.getCreationTimeUTCString());
    }
    ApplicationProperties applicationProperties = new ApplicationProperties(userProperties);
    outgoingMessage.setApplicationProperties(applicationProperties);
    Map<Symbol, Object> messageAnnotationsMap = new HashMap<>();
    if (message.isSecurityMessage()) {
        messageAnnotationsMap.put(Symbol.valueOf(MessageProperty.IOTHUB_SECURITY_INTERFACE_ID), MessageProperty.IOTHUB_SECURITY_INTERFACE_ID_VALUE);
    }
    if (message.getComponentName() != null && !message.getComponentName().isEmpty()) {
        messageAnnotationsMap.put(Symbol.valueOf(MessageProperty.COMPONENT_ID), message.getComponentName());
    }
    MessageAnnotations messageAnnotations = new MessageAnnotations(messageAnnotationsMap);
    outgoingMessage.setMessageAnnotations(messageAnnotations);
    Binary binary = new Binary(message.getBytes());
    Section section = new Data(binary);
    outgoingMessage.setBody(section);
    return outgoingMessage;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) Data(org.apache.qpid.proton.amqp.messaging.Data) Properties(org.apache.qpid.proton.amqp.messaging.Properties) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) Section(org.apache.qpid.proton.amqp.messaging.Section) MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations) MessageProperty(com.microsoft.azure.sdk.iot.device.MessageProperty) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) Binary(org.apache.qpid.proton.amqp.Binary) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl)

Example 19 with ApplicationProperties

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

the class AmqpsTelemetrySenderLinkHandler method iotHubMessageToProtonMessage.

@Override
protected MessageImpl iotHubMessageToProtonMessage(Message message) {
    if ((message.getMessageType() == null) || (message.getMessageType() == MessageType.DEVICE_TELEMETRY)) {
        MessageImpl protonMessage = super.iotHubMessageToProtonMessage(message);
        if (message.getOutputName() != null) {
            if (protonMessage.getApplicationProperties() != null && protonMessage.getApplicationProperties().getValue() != null) {
                Map<String, Object> userProperties = new HashMap<>();
                userProperties.put(MessageProperty.OUTPUT_NAME_PROPERTY, message.getOutputName());
                userProperties.putAll(protonMessage.getApplicationProperties().getValue());
                protonMessage.setApplicationProperties(new ApplicationProperties(userProperties));
            }
        }
        return protonMessage;
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl)

Example 20 with ApplicationProperties

use of org.apache.qpid.proton.amqp.messaging.ApplicationProperties in project hono by eclipse.

the class RequestResponseApiConstants method getAmqpReply.

/**
 * Creates an AMQP message from a response to a service invocation.
 *
 * @param endpoint The service endpoint that the operation has been invoked on.
 * @param response The response message.
 * @return The AMQP message.
 * @throws NullPointerException if endpoint is {@code null}.
 * @throws IllegalArgumentException if the response does not contain a correlation ID.
 */
public static final Message getAmqpReply(final String endpoint, final EventBusMessage response) {
    Objects.requireNonNull(endpoint);
    Objects.requireNonNull(response);
    final Object correlationId = response.getCorrelationId();
    if (correlationId == null) {
        throw new IllegalArgumentException("response must contain correlation ID");
    }
    final String tenantId = response.getTenant();
    final String deviceId = response.getDeviceId();
    final Integer status = response.getStatus();
    final String cacheDirective = response.getCacheDirective();
    final JsonObject payload = response.getJsonPayload();
    final ResourceIdentifier address = ResourceIdentifier.from(endpoint, tenantId, deviceId);
    final Message message = ProtonHelper.message();
    message.setMessageId(UUID.randomUUID().toString());
    message.setCorrelationId(correlationId);
    message.setAddress(address.toString());
    final Map<String, Object> map = new HashMap<>();
    map.put(MessageHelper.APP_PROPERTY_STATUS, status);
    if (tenantId != null) {
        map.put(MessageHelper.APP_PROPERTY_TENANT_ID, tenantId);
    }
    if (deviceId != null) {
        map.put(MessageHelper.APP_PROPERTY_DEVICE_ID, deviceId);
    }
    if (cacheDirective != null) {
        map.put(MessageHelper.APP_PROPERTY_CACHE_CONTROL, cacheDirective);
    }
    message.setApplicationProperties(new ApplicationProperties(map));
    MessageHelper.setJsonPayload(message, payload);
    return message;
}
Also used : Message(org.apache.qpid.proton.message.Message) HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)41 HashMap (java.util.HashMap)25 MessageImpl (org.apache.qpid.proton.message.impl.MessageImpl)14 Properties (org.apache.qpid.proton.amqp.messaging.Properties)12 AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)11 Message (org.apache.qpid.proton.message.Message)11 Binary (org.apache.qpid.proton.amqp.Binary)10 MessageAnnotations (org.apache.qpid.proton.amqp.messaging.MessageAnnotations)10 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)9 Test (org.junit.Test)9 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)8 Data (org.apache.qpid.proton.amqp.messaging.Data)8 Symbol (org.apache.qpid.proton.amqp.Symbol)7 Section (org.apache.qpid.proton.amqp.messaging.Section)7 Map (java.util.Map)6 Header (org.apache.qpid.proton.amqp.messaging.Header)6 Test (org.junit.jupiter.api.Test)5 Buffer (io.vertx.core.buffer.Buffer)3 JsonObject (io.vertx.core.json.JsonObject)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3