use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class MessageTransformationTest method testPropertiesButNoHeadersEncodeDecode.
@Test
public void testPropertiesButNoHeadersEncodeDecode() throws Exception {
Message incomingMessage = Proton.message();
incomingMessage.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));
incomingMessage.setMessageId("ID:SomeQualifier:0:0:1");
ICoreMessage core = new AMQPMessage(incomingMessage).toCore();
Message outboudMessage = AMQPConverter.getInstance().fromCore(core).getProtonMessage();
assertNull(outboudMessage.getHeader());
assertNotNull(outboudMessage.getProperties());
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class MessageTransformationTest method testBodyOnlyEncodeDecode.
@Test
public void testBodyOnlyEncodeDecode() throws Exception {
Message incomingMessage = Proton.message();
incomingMessage.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));
ICoreMessage core = new AMQPMessage(incomingMessage).toCore();
Message outboudMessage = AMQPConverter.getInstance().fromCore(core).getProtonMessage();
assertNull(outboudMessage.getHeader());
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class MessageTransformationTest method testComplexQpidJMSMessageEncodeDecode.
@Test
public void testComplexQpidJMSMessageEncodeDecode() throws Exception {
Map<String, Object> applicationProperties = new HashMap<>();
Map<Symbol, Object> messageAnnotations = new HashMap<>();
applicationProperties.put("property-1", "string-1");
applicationProperties.put("property-2", 512);
applicationProperties.put("property-3", true);
applicationProperties.put("property-4", "string-2");
applicationProperties.put("property-5", 512);
applicationProperties.put("property-6", true);
applicationProperties.put("property-7", "string-3");
applicationProperties.put("property-8", 512);
applicationProperties.put("property-9", true);
messageAnnotations.put(Symbol.valueOf("x-opt-jms-msg-type"), 0);
messageAnnotations.put(Symbol.valueOf("x-opt-jms-dest"), 0);
messageAnnotations.put(Symbol.valueOf("x-opt-jms-reply-to"), 0);
messageAnnotations.put(Symbol.valueOf("x-opt-delivery-delay"), 2000);
Message message = Proton.message();
// Header Values
message.setPriority((short) 9);
message.setDurable(true);
message.setDeliveryCount(2);
message.setTtl(5000);
// Properties
message.setMessageId("ID:SomeQualifier:0:0:1");
message.setGroupId("Group-ID-1");
message.setGroupSequence(15);
message.setAddress("queue://test-queue");
message.setReplyTo("queue://reply-queue");
message.setCreationTime(System.currentTimeMillis());
message.setContentType("text/plain");
message.setCorrelationId("ID:SomeQualifier:0:7:9");
message.setUserId("username".getBytes(StandardCharsets.UTF_8));
// Application Properties / Message Annotations / Body
message.setApplicationProperties(new ApplicationProperties(applicationProperties));
message.setMessageAnnotations(new MessageAnnotations(messageAnnotations));
message.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));
ICoreMessage core = new AMQPMessage(message).toCore();
Message outboudMessage = AMQPConverter.getInstance().fromCore(core).getProtonMessage();
assertEquals(10, outboudMessage.getApplicationProperties().getValue().size());
assertEquals(4, outboudMessage.getMessageAnnotations().getValue().size());
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class EmbedMessageUtil method embedAsCoreMessage.
public static ICoreMessage embedAsCoreMessage(Message source) {
if (source instanceof ICoreMessage) {
return (ICoreMessage) source;
} else {
Persister persister = source.getPersister();
CoreMessage message = new CoreMessage(source.getMessageID(), persister.getEncodeSize(source) + signature.length + CoreMessage.BODY_OFFSET).setType(Message.EMBEDDED_TYPE);
ActiveMQBuffer buffer = message.getBodyBuffer();
buffer.writeBytes(signature);
persister.encode(buffer, source);
return message;
}
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class SimpleTransformer method transform.
@Override
public Message transform(final Message messageParameter) {
ICoreMessage message = messageParameter.toCore();
SimpleString oldProp = (SimpleString) message.getObjectProperty(new SimpleString("wibble"));
if (!oldProp.equals(new SimpleString("bing"))) {
throw new IllegalStateException("Wrong property value!!");
}
// Change a property
message.putStringProperty(new SimpleString("wibble"), new SimpleString("bong"));
// Change the body
ActiveMQBuffer buffer = message.getBodyBuffer();
buffer.readerIndex(0);
String str = buffer.readString();
if (!str.equals("doo be doo be doo be doo")) {
throw new IllegalStateException("Wrong body!!");
}
buffer.clear();
buffer.writeString("dee be dee be dee be dee");
return message;
}
Aggregations