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;
}
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;
}
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);
}
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;
}
Aggregations