Search in sources :

Example 21 with MessageAnnotations

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

the class AMQPMessage method removeSymbol.

private Object removeSymbol(Symbol symbol) {
    MessageAnnotations annotations = getMessageAnnotations();
    Map<Symbol, Object> mapAnnotations = annotations != null ? annotations.getValue() : null;
    if (mapAnnotations != null) {
        return mapAnnotations.remove(symbol);
    }
    return null;
}
Also used : MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations) Symbol(org.apache.qpid.proton.amqp.Symbol)

Example 22 with MessageAnnotations

use of org.apache.qpid.proton.amqp.messaging.MessageAnnotations in project azure-service-bus-java by Azure.

the class MessageConverter method convertBrokeredMessageToAmqpMessage.

public static org.apache.qpid.proton.message.Message convertBrokeredMessageToAmqpMessage(Message brokeredMessage) {
    org.apache.qpid.proton.message.Message amqpMessage = Proton.message();
    if (brokeredMessage.getBody() != null) {
        amqpMessage.setBody(new Data(new Binary(brokeredMessage.getBody())));
    }
    if (brokeredMessage.getProperties() != null) {
        amqpMessage.setApplicationProperties(new ApplicationProperties(brokeredMessage.getProperties()));
    }
    if (brokeredMessage.getTimeToLive() != null) {
        amqpMessage.setTtl(brokeredMessage.getTimeToLive().toMillis());
    }
    amqpMessage.setMessageId(brokeredMessage.getMessageId());
    amqpMessage.setContentType(brokeredMessage.getContentType());
    amqpMessage.setCorrelationId(brokeredMessage.getCorrelationId());
    amqpMessage.setSubject(brokeredMessage.getLabel());
    amqpMessage.getProperties().setTo(brokeredMessage.getTo());
    amqpMessage.setReplyTo(brokeredMessage.getReplyTo());
    amqpMessage.setReplyToGroupId(brokeredMessage.getReplyToSessionId());
    amqpMessage.setGroupId(brokeredMessage.getSessionId());
    Map<Symbol, Object> messageAnnotationsMap = new HashMap<Symbol, Object>();
    if (brokeredMessage.getScheduledEnqueuedTimeUtc() != null) {
        messageAnnotationsMap.put(Symbol.valueOf(ClientConstants.SCHEDULEDENQUEUETIMENAME), Date.from(brokeredMessage.getScheduledEnqueuedTimeUtc()));
    }
    if (!StringUtil.isNullOrEmpty(brokeredMessage.getPartitionKey())) {
        messageAnnotationsMap.put(Symbol.valueOf(ClientConstants.PARTITIONKEYNAME), brokeredMessage.getPartitionKey());
    }
    amqpMessage.setMessageAnnotations(new MessageAnnotations(messageAnnotationsMap));
    return amqpMessage;
}
Also used : HashMap(java.util.HashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) Data(org.apache.qpid.proton.amqp.messaging.Data) Binary(org.apache.qpid.proton.amqp.Binary)

Example 23 with MessageAnnotations

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

the class AmqpsTwinSenderLinkHandler method setMessageAnnotationMapOnProtonMessage.

private static void setMessageAnnotationMapOnProtonMessage(MessageImpl protonMessage, DeviceOperations deviceOperationType, String deviceTwinMessageVersion) {
    Map<Symbol, Object> messageAnnotationsMap = new HashMap<>();
    switch(deviceOperationType) {
        case DEVICE_OPERATION_TWIN_GET_REQUEST:
            messageAnnotationsMap.put(Symbol.valueOf(MESSAGE_ANNOTATION_FIELD_KEY_OPERATION), MESSAGE_ANNOTATION_FIELD_VALUE_GET);
            break;
        case DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_REQUEST:
            messageAnnotationsMap.put(Symbol.valueOf(MESSAGE_ANNOTATION_FIELD_KEY_OPERATION), MESSAGE_ANNOTATION_FIELD_VALUE_PATCH);
            messageAnnotationsMap.put(Symbol.valueOf(MESSAGE_ANNOTATION_FIELD_KEY_RESOURCE), MESSAGE_ANNOTATION_FIELD_VALUE_PROPERTIES_REPORTED);
            if (deviceTwinMessageVersion != null) {
                try {
                    messageAnnotationsMap.put(Symbol.valueOf(MESSAGE_ANNOTATION_FIELD_KEY_VERSION), Long.parseLong(deviceTwinMessageVersion));
                } catch (NumberFormatException e) {
                    log.error("Failed to convert device twin version into a long, can't add version annotation to message.");
                }
            }
            break;
        case DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_REQUEST:
            messageAnnotationsMap.put(Symbol.valueOf(MESSAGE_ANNOTATION_FIELD_KEY_OPERATION), MESSAGE_ANNOTATION_FIELD_VALUE_PUT);
            messageAnnotationsMap.put(Symbol.valueOf(MESSAGE_ANNOTATION_FIELD_KEY_RESOURCE), MESSAGE_ANNOTATION_FIELD_VALUE_NOTIFICATIONS_TWIN_PROPERTIES_DESIRED);
            break;
        case DEVICE_OPERATION_TWIN_UNSUBSCRIBE_DESIRED_PROPERTIES_REQUEST:
            messageAnnotationsMap.put(Symbol.valueOf(MESSAGE_ANNOTATION_FIELD_KEY_OPERATION), MESSAGE_ANNOTATION_FIELD_VALUE_DELETE);
            messageAnnotationsMap.put(Symbol.valueOf(MESSAGE_ANNOTATION_FIELD_KEY_RESOURCE), MESSAGE_ANNOTATION_FIELD_VALUE_NOTIFICATIONS_TWIN_PROPERTIES_DESIRED);
            break;
        default:
            log.error("Unrecognized device operation type during conversion of iothub message into proton message");
    }
    if (protonMessage.getMessageAnnotations() != null && protonMessage.getMessageAnnotations().getValue() != null) {
        messageAnnotationsMap.putAll(protonMessage.getMessageAnnotations().getValue());
    }
    MessageAnnotations messageAnnotations = new MessageAnnotations(messageAnnotationsMap);
    protonMessage.setMessageAnnotations(messageAnnotations);
}
Also used : HashMap(java.util.HashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations)

Example 24 with MessageAnnotations

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

the class AmqpsTwinReceiverLinkHandler method protonMessageToIoTHubMessage.

@Override
protected IotHubTransportMessage protonMessageToIoTHubMessage(AmqpsMessage protonMsg) {
    IotHubTransportMessage iotHubTransportMessage = super.protonMessageToIoTHubMessage(protonMsg);
    MessageCallback messageCallback = deviceClientConfig.getDeviceTwinMessageCallback();
    Object messageContext = deviceClientConfig.getDeviceTwinMessageContext();
    iotHubTransportMessage.setMessageCallback(messageCallback);
    iotHubTransportMessage.setMessageCallbackContext(messageContext);
    iotHubTransportMessage.setMessageType(MessageType.DEVICE_TWIN);
    iotHubTransportMessage.setDeviceOperationType(DEVICE_OPERATION_UNKNOWN);
    MessageAnnotations messageAnnotations = protonMsg.getMessageAnnotations();
    if (messageAnnotations != null) {
        for (Map.Entry<Symbol, Object> entry : messageAnnotations.getValue().entrySet()) {
            Symbol key = entry.getKey();
            Object value = entry.getValue();
            if (key.toString().equals(MESSAGE_ANNOTATION_FIELD_KEY_STATUS)) {
                iotHubTransportMessage.setStatus(value.toString());
            } else if (key.toString().equals(MESSAGE_ANNOTATION_FIELD_KEY_VERSION)) {
                iotHubTransportMessage.setVersion(value.toString());
            } else if (key.toString().equals(MESSAGE_ANNOTATION_FIELD_KEY_RESOURCE) && value.toString().equals(MESSAGE_ANNOTATION_FIELD_VALUE_PROPERTIES_DESIRED)) {
                iotHubTransportMessage.setDeviceOperationType(DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE);
            }
        }
    }
    Properties properties = protonMsg.getProperties();
    if (properties != null && properties.getCorrelationId() != null) {
        iotHubTransportMessage.setCorrelationId(properties.getCorrelationId().toString());
        if (twinOperationCorrelationMap.containsKey(properties.getCorrelationId().toString())) {
            DeviceOperations deviceOperations = twinOperationCorrelationMap.get(properties.getCorrelationId().toString());
            switch(deviceOperations) {
                case DEVICE_OPERATION_TWIN_GET_REQUEST:
                    iotHubTransportMessage.setDeviceOperationType(DEVICE_OPERATION_TWIN_GET_RESPONSE);
                    break;
                case DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_REQUEST:
                    iotHubTransportMessage.setDeviceOperationType(DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_RESPONSE);
                    break;
                case DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_REQUEST:
                    iotHubTransportMessage.setDeviceOperationType(DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE);
                    break;
                case DEVICE_OPERATION_TWIN_UNSUBSCRIBE_DESIRED_PROPERTIES_REQUEST:
                    iotHubTransportMessage.setDeviceOperationType(DEVICE_OPERATION_TWIN_UNSUBSCRIBE_DESIRED_PROPERTIES_RESPONSE);
                    break;
                default:
                    log.error("Unrecognized device operation type during conversion of proton message into an iothub message");
            }
            this.twinOperationCorrelationMap.remove(properties.getCorrelationId().toString());
        }
    } else if (iotHubTransportMessage.getDeviceOperationType() == DEVICE_OPERATION_UNKNOWN) {
        iotHubTransportMessage.setDeviceOperationType(DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE);
        if (iotHubTransportMessage.getStatus() == null || iotHubTransportMessage.getStatus().isEmpty()) {
            iotHubTransportMessage.setStatus(DEFAULT_STATUS_CODE);
        }
    }
    return iotHubTransportMessage;
}
Also used : DeviceOperations(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations) MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations) Symbol(org.apache.qpid.proton.amqp.Symbol) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) Properties(org.apache.qpid.proton.amqp.messaging.Properties) Map(java.util.Map) MessageCallback(com.microsoft.azure.sdk.iot.device.MessageCallback)

Aggregations

MessageAnnotations (org.apache.qpid.proton.amqp.messaging.MessageAnnotations)24 Symbol (org.apache.qpid.proton.amqp.Symbol)19 HashMap (java.util.HashMap)15 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)11 Message (org.apache.qpid.proton.message.Message)10 AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)6 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)6 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)5 ServerJMSMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage)5 Binary (org.apache.qpid.proton.amqp.Binary)5 Properties (org.apache.qpid.proton.amqp.messaging.Properties)5 ServerJMSBytesMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage)4 ServerJMSMapMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage)4 ServerJMSObjectMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage)4 ServerJMSStreamMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage)4 ServerJMSTextMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage)4 Section (org.apache.qpid.proton.amqp.messaging.Section)4 Map (java.util.Map)3 Data (org.apache.qpid.proton.amqp.messaging.Data)3 Header (org.apache.qpid.proton.amqp.messaging.Header)3