use of org.apache.qpid.proton.amqp.messaging.MessageAnnotations in project activemq-artemis by apache.
the class AMQPMessage method setSymbol.
private void setSymbol(Symbol symbol, Object value) {
MessageAnnotations annotations = getMessageAnnotations();
if (annotations == null) {
_messageAnnotations = new MessageAnnotations(new HashMap<>());
annotations = _messageAnnotations;
}
Map<Symbol, Object> mapAnnotations = annotations != null ? annotations.getValue() : null;
if (mapAnnotations != null) {
mapAnnotations.put(symbol, value);
}
}
use of org.apache.qpid.proton.amqp.messaging.MessageAnnotations in project activemq-artemis by apache.
the class AMQPMessage method getSymbol.
private Object getSymbol(Symbol symbol) {
MessageAnnotations annotations = getMessageAnnotations();
Map<Symbol, Object> mapAnnotations = annotations != null ? annotations.getValue() : null;
if (mapAnnotations != null) {
return mapAnnotations.get(symbol);
}
return null;
}
use of org.apache.qpid.proton.amqp.messaging.MessageAnnotations in project activemq-artemis by apache.
the class AmqpCoreConverter method populateMessage.
@SuppressWarnings("unchecked")
protected static ServerJMSMessage populateMessage(ServerJMSMessage jms, org.apache.qpid.proton.message.Message amqp) throws Exception {
Header header = amqp.getHeader();
if (header != null) {
jms.setBooleanProperty(JMS_AMQP_HEADER, true);
if (header.getDurable() != null) {
jms.setBooleanProperty(JMS_AMQP_HEADER_DURABLE, true);
jms.setJMSDeliveryMode(header.getDurable().booleanValue() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
} else {
jms.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
if (header.getPriority() != null) {
jms.setBooleanProperty(JMS_AMQP_HEADER_PRIORITY, true);
jms.setJMSPriority(header.getPriority().intValue());
} else {
jms.setJMSPriority(javax.jms.Message.DEFAULT_PRIORITY);
}
if (header.getFirstAcquirer() != null) {
jms.setBooleanProperty(JMS_AMQP_FIRST_ACQUIRER, header.getFirstAcquirer());
}
if (header.getDeliveryCount() != null) {
// AMQP Delivery Count counts only failed delivers where JMS
// Delivery Count should include the original delivery in the count.
jms.setLongProperty("JMSXDeliveryCount", header.getDeliveryCount().longValue() + 1);
}
} else {
jms.setJMSPriority((byte) javax.jms.Message.DEFAULT_PRIORITY);
jms.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
final MessageAnnotations ma = amqp.getMessageAnnotations();
if (ma != null) {
for (Map.Entry<?, ?> entry : ma.getValue().entrySet()) {
String key = entry.getKey().toString();
if ("x-opt-delivery-time".equals(key) && entry.getValue() != null) {
long deliveryTime = ((Number) entry.getValue()).longValue();
jms.setLongProperty(HDR_SCHEDULED_DELIVERY_TIME.toString(), deliveryTime);
} else if ("x-opt-delivery-delay".equals(key) && entry.getValue() != null) {
long delay = ((Number) entry.getValue()).longValue();
if (delay > 0) {
jms.setLongProperty(HDR_SCHEDULED_DELIVERY_TIME.toString(), System.currentTimeMillis() + delay);
}
}
setProperty(jms, JMS_AMQP_MESSAGE_ANNOTATION_PREFIX + key, entry.getValue());
}
}
final ApplicationProperties ap = amqp.getApplicationProperties();
if (ap != null) {
for (Map.Entry<String, Object> entry : (Set<Map.Entry<String, Object>>) ap.getValue().entrySet()) {
setProperty(jms, entry.getKey(), entry.getValue());
}
}
final Properties properties = amqp.getProperties();
if (properties != null) {
if (properties.getMessageId() != null) {
jms.setJMSMessageID(AMQPMessageIdHelper.INSTANCE.toMessageIdString(properties.getMessageId()));
}
Binary userId = properties.getUserId();
if (userId != null) {
jms.setStringProperty("JMSXUserID", new String(userId.getArray(), userId.getArrayOffset(), userId.getLength(), StandardCharsets.UTF_8));
}
if (properties.getTo() != null) {
jms.setJMSDestination(new ServerDestination(properties.getTo()));
}
if (properties.getSubject() != null) {
jms.setJMSType(properties.getSubject());
}
if (properties.getReplyTo() != null) {
jms.setJMSReplyTo(new ServerDestination(properties.getReplyTo()));
}
if (properties.getCorrelationId() != null) {
jms.setJMSCorrelationID(AMQPMessageIdHelper.INSTANCE.toCorrelationIdString(properties.getCorrelationId()));
}
if (properties.getContentType() != null) {
jms.setStringProperty(JMS_AMQP_CONTENT_TYPE, properties.getContentType().toString());
}
if (properties.getContentEncoding() != null) {
jms.setStringProperty(JMS_AMQP_CONTENT_ENCODING, properties.getContentEncoding().toString());
}
if (properties.getCreationTime() != null) {
jms.setJMSTimestamp(properties.getCreationTime().getTime());
}
if (properties.getGroupId() != null) {
jms.setStringProperty("_AMQ_GROUP_ID", properties.getGroupId());
}
if (properties.getGroupSequence() != null) {
jms.setIntProperty("JMSXGroupSeq", properties.getGroupSequence().intValue());
}
if (properties.getReplyToGroupId() != null) {
jms.setStringProperty(JMS_AMQP_REPLYTO_GROUP_ID, properties.getReplyToGroupId());
}
if (properties.getAbsoluteExpiryTime() != null) {
jms.setJMSExpiration(properties.getAbsoluteExpiryTime().getTime());
}
}
// If the jms expiration has not yet been set...
if (header != null && jms.getJMSExpiration() == 0) {
// Then lets try to set it based on the message ttl.
long ttl = javax.jms.Message.DEFAULT_TIME_TO_LIVE;
if (header.getTtl() != null) {
ttl = header.getTtl().longValue();
}
if (ttl == 0) {
jms.setJMSExpiration(0);
} else {
jms.setJMSExpiration(System.currentTimeMillis() + ttl);
}
}
final Footer fp = amqp.getFooter();
if (fp != null) {
for (Map.Entry<Object, Object> entry : (Set<Map.Entry<Object, Object>>) fp.getValue().entrySet()) {
String key = entry.getKey().toString();
setProperty(jms, JMS_AMQP_FOOTER_PREFIX + key, entry.getValue());
}
}
return jms;
}
use of org.apache.qpid.proton.amqp.messaging.MessageAnnotations 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;
}
use of org.apache.qpid.proton.amqp.messaging.MessageAnnotations in project activemq-artemis by apache.
the class AMQPMessageSupportTest method testGetMessageAnnotationWhenMessageHasEmptyAnnotationsMap.
@Test
public void testGetMessageAnnotationWhenMessageHasEmptyAnnotationsMap() {
Map<Symbol, Object> messageAnnotationsMap = new HashMap<>();
Message message = Proton.message();
message.setMessageAnnotations(new MessageAnnotations(messageAnnotationsMap));
assertNull(AMQPMessageSupport.getMessageAnnotation("x-opt-test", message));
}
Aggregations