use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class TestConversions method testSimpleConversionMap.
@Test
public void testSimpleConversionMap() throws Exception {
Map<String, Object> mapprop = createPropertiesMap();
ApplicationProperties properties = new ApplicationProperties(mapprop);
MessageImpl message = (MessageImpl) Message.Factory.create();
message.setApplicationProperties(properties);
Map<String, Object> mapValues = new HashMap<>();
mapValues.put("somestr", "value");
mapValues.put("someint", Integer.valueOf(1));
message.setBody(new AmqpValue(mapValues));
AMQPMessage encodedMessage = new AMQPMessage(message);
ICoreMessage serverMessage = encodedMessage.toCore();
serverMessage.getReadOnlyBodyBuffer();
ServerJMSMapMessage mapMessage = (ServerJMSMapMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
mapMessage.decode();
verifyProperties(mapMessage);
Assert.assertEquals(1, mapMessage.getInt("someint"));
Assert.assertEquals("value", mapMessage.getString("somestr"));
AMQPMessage newAMQP = CoreAmqpConverter.fromCore(mapMessage.getInnerMessage());
System.out.println(newAMQP.getProtonMessage().getBody());
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class TestConversions method testAmqpValueOfBooleanIsPassedThrough.
@Test
public void testAmqpValueOfBooleanIsPassedThrough() throws Exception {
Map<String, Object> mapprop = createPropertiesMap();
ApplicationProperties properties = new ApplicationProperties(mapprop);
MessageImpl message = (MessageImpl) Message.Factory.create();
message.setApplicationProperties(properties);
byte[] bodyBytes = new byte[4];
for (int i = 0; i < bodyBytes.length; i++) {
bodyBytes[i] = (byte) 0xff;
}
message.setBody(new AmqpValue(new Boolean(true)));
AMQPMessage encodedMessage = new AMQPMessage(message);
ICoreMessage serverMessage = encodedMessage.toCore();
verifyProperties(ServerJMSMessage.wrapCoreMessage(serverMessage));
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class TestConversions method testSimpleConversionStream.
@Test
public void testSimpleConversionStream() throws Exception {
Map<String, Object> mapprop = createPropertiesMap();
ApplicationProperties properties = new ApplicationProperties(mapprop);
MessageImpl message = (MessageImpl) Message.Factory.create();
message.setApplicationProperties(properties);
List<Object> objects = new LinkedList<>();
objects.add(new Integer(10));
objects.add("10");
message.setBody(new AmqpSequence(objects));
AMQPMessage encodedMessage = new AMQPMessage(message);
ICoreMessage serverMessage = encodedMessage.toCore();
ServerJMSStreamMessage streamMessage = (ServerJMSStreamMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
verifyProperties(streamMessage);
streamMessage.reset();
assertEquals(10, streamMessage.readInt());
assertEquals("10", streamMessage.readString());
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class JMSMappingInboundTransformerTest method testCreateBytesMessageFromNoBodySectionAndContentType.
// ----- Null Body Section ------------------------------------------------//
/**
* Test that a message with no body section, but with the content type set to
* {@value AMQPMessageSupport#OCTET_STREAM_CONTENT_TYPE} results in a BytesMessage
*
* @throws Exception
* if an error occurs during the test.
*/
@Test
public void testCreateBytesMessageFromNoBodySectionAndContentType() throws Exception {
Message message = Message.Factory.create();
message.setContentType(AMQPMessageSupport.OCTET_STREAM_CONTENT_TYPE);
AMQPMessage messageEncode = new AMQPMessage(message);
ICoreMessage coreMessage = messageEncode.toCore();
javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(coreMessage);
assertNotNull("Message should not be null", jmsMessage);
assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass());
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class StompSession method sendMessage.
@Override
public int sendMessage(MessageReference ref, Message serverMessage, final ServerConsumer consumer, int deliveryCount) {
ICoreMessage coreMessage = serverMessage.toCore();
LargeServerMessageImpl largeMessage = null;
ICoreMessage newServerMessage = serverMessage.toCore();
try {
StompSubscription subscription = subscriptions.get(consumer.getID());
// subscription might be null if the consumer was closed
if (subscription == null)
return 0;
StompFrame frame;
ActiveMQBuffer buffer = coreMessage.getDataBuffer();
frame = connection.createStompMessage(newServerMessage, buffer, subscription, deliveryCount);
int length = frame.getEncodedSize();
if (subscription.getAck().equals(Stomp.Headers.Subscribe.AckModeValues.AUTO)) {
if (manager.send(connection, frame)) {
final long messageID = newServerMessage.getMessageID();
final long consumerID = consumer.getID();
// this will be called after the delivery is complete
// we can't call session.ack within the delivery
// as it could dead lock.
afterDeliveryTasks.offer(new PendingTask() {
@Override
public void run() throws Exception {
// we ack and commit only if the send is successful
session.acknowledge(consumerID, messageID);
session.commit();
}
});
}
} else {
messagesToAck.put(newServerMessage.getMessageID(), new Pair<>(consumer.getID(), length));
// Must send AFTER adding to messagesToAck - or could get acked from client BEFORE it's been added!
manager.send(connection, frame);
}
return length;
} catch (Exception e) {
if (ActiveMQStompProtocolLogger.LOGGER.isDebugEnabled()) {
ActiveMQStompProtocolLogger.LOGGER.debug(e);
}
return 0;
} finally {
if (largeMessage != null) {
largeMessage.releaseResources();
largeMessage = null;
}
}
}
Aggregations