use of org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.
the class MessageConverter_to_1_0 method createMessageAnnotation.
public static MessageAnnotations createMessageAnnotation(final EncodingRetainingSection<?> bodySection, final String contentMimeType) {
MessageAnnotations messageAnnotations = null;
final Symbol key = Symbol.valueOf("x-opt-jms-msg-type");
if (contentMimeType != null) {
if (TEXT_CONTENT_TYPES.matcher(contentMimeType).matches()) {
messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, TEXT_MESSAGE.getType()));
} else if (BYTES_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, BYTES_MESSAGE.getType()));
} else if (MAP_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
if (isSectionValidForJmsMap(bodySection)) {
messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, MAP_MESSAGE.getType()));
}
} else if (LIST_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
if (isSectionValidForJmsList(bodySection)) {
messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, STREAM_MESSAGE.getType()));
}
} else if (OBJECT_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, OBJECT_MESSAGE.getType()));
}
} else if (bodySection instanceof AmqpValueSection && bodySection.getValue() == null) {
messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, MESSAGE.getType()));
}
return messageAnnotations;
}
use of org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.
the class ConsumerTarget_1_0Test method createTestMessage.
private Message_1_0 createTestMessage(final Header header, long arrivalTime) {
DeliveryAnnotationsSection deliveryAnnotations = new DeliveryAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
MessageAnnotationsSection messageAnnotations = new MessageAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
ApplicationPropertiesSection applicationProperties = new ApplicationProperties(Collections.emptyMap()).createEncodingRetainingSection();
FooterSection footer = new Footer(Collections.emptyMap()).createEncodingRetainingSection();
MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations, messageAnnotations, new Properties().createEncodingRetainingSection(), applicationProperties, footer, arrivalTime, 0);
final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
when(storedMessage.getContent(eq(0), anyInt())).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
when(storedMessage.getMetaData()).thenReturn(metaData);
return new Message_1_0(storedMessage);
}
use of org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations in project storm by apache.
the class EventHubReceiverImpl method createMessageId.
private MessageId createMessageId(Message message) {
String offset = null;
long sequenceNumber = 0;
for (Section section : message.getPayload()) {
if (section instanceof MessageAnnotations) {
MessageAnnotations annotations = (MessageAnnotations) section;
HashMap annonationMap = (HashMap) annotations.getValue();
if (annonationMap.containsKey(OffsetKey)) {
offset = (String) annonationMap.get(OffsetKey);
}
if (annonationMap.containsKey(SequenceNumberKey)) {
sequenceNumber = (Long) annonationMap.get(SequenceNumberKey);
}
}
}
return MessageId.create(partitionId, offset, sequenceNumber);
}
use of org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_8Test method testConversionOfAbsoluteExpiryTimeTakesPrecedenceOverTTL.
public void testConversionOfAbsoluteExpiryTimeTakesPrecedenceOverTTL() {
long ttl = 10000;
final long time = System.currentTimeMillis();
long absoluteExpiryTime = time + ttl;
long arrivalTime = time + 1;
Header header = new Header();
header.setTtl(UnsignedInteger.valueOf(ttl));
Properties properties = new Properties();
properties.setAbsoluteExpiryTime(new Date(absoluteExpiryTime));
Message_1_0 message = createTestMessage(header, new DeliveryAnnotations(Collections.emptyMap()), new MessageAnnotations(Collections.emptyMap()), properties, new ApplicationProperties(Collections.emptyMap()), arrivalTime);
final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
BasicContentHeaderProperties convertedProperties = convertedMessage.getContentHeaderBody().getProperties();
assertEquals("Unexpected expiration", absoluteExpiryTime, convertedProperties.getExpiration());
}
use of org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.
the class MessageConverter_v1_0_to_InternalTest method testNoBodyWithUnknownMessageAnnotation.
public void testNoBodyWithUnknownMessageAnnotation() throws Exception {
Message_1_0 sourceMessage = createTestMessage(new MessageAnnotations(Collections.singletonMap(Symbol.valueOf("x-opt-jms-msg-type"), (byte) 11)), null);
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", null, convertedMessage.getMessageHeader().getMimeType());
assertEquals("Unexpected content", null, convertedMessage.getMessageBody());
}
Aggregations