Search in sources :

Example 46 with AMQPMessage

use of org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage 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());
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Message(org.apache.qpid.proton.message.Message) HashMap(java.util.HashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) MessageAnnotations(org.apache.qpid.proton.amqp.messaging.MessageAnnotations) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 47 with AMQPMessage

use of org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage in project activemq-artemis by apache.

the class MessageJournalTest method testStoreAMQP.

@Test
public void testStoreAMQP() throws Throwable {
    ActiveMQServer server = createServer(true);
    server.start();
    ProtonProtocolManagerFactory factory = (ProtonProtocolManagerFactory) server.getRemotingService().getProtocolFactoryMap().get("AMQP");
    Message protonJMessage = Message.Factory.create();
    AMQPMessage message = new AMQPMessage(protonJMessage);
    message.setMessageID(333);
    Assert.assertNotNull(factory);
    server.getStorageManager().storeMessage(message);
    server.getStorageManager().stop();
    JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
    List<RecordInfo> committedRecords = new LinkedList<>();
    List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    TransactionFailureCallback transactionFailure = new TransactionFailureCallback() {

        @Override
        public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
        }
    };
    try {
        journalStorageManager.getMessageJournal().start();
        journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
        Assert.assertEquals(1, committedRecords.size());
    } finally {
        journalStorageManager.getMessageJournal().stop();
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Message(org.apache.qpid.proton.message.Message) ProtonProtocolManagerFactory(org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManagerFactory) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) List(java.util.List) LinkedList(java.util.LinkedList) TransactionFailureCallback(org.apache.activemq.artemis.core.journal.TransactionFailureCallback) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) LinkedList(java.util.LinkedList) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) Test(org.junit.Test)

Example 48 with AMQPMessage

use of org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage in project activemq-artemis by apache.

the class ProtonServerSenderContext method deliverMessage.

/**
 * handle an out going message from ActiveMQ Artemis, send via the Proton Sender
 */
public int deliverMessage(MessageReference messageReference, int deliveryCount, Connection transportConnection) throws Exception {
    if (closed) {
        return 0;
    }
    AMQPMessage message = CoreAmqpConverter.checkAMQP(messageReference.getMessage());
    sessionSPI.invokeOutgoing(message, (ActiveMQProtonRemotingConnection) transportConnection.getProtocolConnection());
    // presettle means we can settle the message on the dealer side before we send it, i.e.
    // for browsers
    boolean preSettle = sender.getRemoteSenderSettleMode() == SenderSettleMode.SETTLED;
    // we only need a tag if we are going to settle later
    byte[] tag = preSettle ? new byte[0] : protonSession.getTag();
    // Let the Message decide how to present the message bytes
    ByteBuf sendBuffer = message.getSendBuffer(deliveryCount);
    try {
        int size = sendBuffer.writerIndex();
        while (!connection.tryLock(1, TimeUnit.SECONDS)) {
            if (closed || sender.getLocalState() == EndpointState.CLOSED) {
                // we return.
                return 0;
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Couldn't get lock on deliverMessage " + this);
                }
            }
        }
        try {
            final Delivery delivery;
            delivery = sender.delivery(tag, 0, tag.length);
            delivery.setMessageFormat((int) message.getMessageFormat());
            delivery.setContext(messageReference);
            if (sendBuffer.hasArray()) {
                // this will avoid a copy.. patch provided by Norman using buffer.array()
                sender.send(sendBuffer.array(), sendBuffer.arrayOffset() + sendBuffer.readerIndex(), sendBuffer.readableBytes());
            } else {
                sender.send(new NettyReadable(sendBuffer));
            }
            if (preSettle) {
                // Presettled means the client implicitly accepts any delivery we send it.
                sessionSPI.ack(null, brokerConsumer, messageReference.getMessage());
                delivery.settle();
            } else {
                sender.advance();
            }
            connection.flush();
        } finally {
            connection.unlock();
        }
        return size;
    } finally {
        sendBuffer.release();
    }
}
Also used : Delivery(org.apache.qpid.proton.engine.Delivery) ByteBuf(io.netty.buffer.ByteBuf) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) NettyReadable(org.apache.activemq.artemis.protocol.amqp.util.NettyReadable)

Example 49 with AMQPMessage

use of org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage in project activemq-artemis by apache.

the class TestConversions method testSimpleConversionBytes.

@Test
public void testSimpleConversionBytes() 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 Data(new Binary(bodyBytes)));
    AMQPMessage encodedMessage = new AMQPMessage(message);
    ICoreMessage serverMessage = encodedMessage.toCore();
    ServerJMSBytesMessage bytesMessage = (ServerJMSBytesMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
    verifyProperties(bytesMessage);
    assertEquals(bodyBytes.length, bytesMessage.getBodyLength());
    byte[] newBodyBytes = new byte[4];
    bytesMessage.readBytes(newBodyBytes);
    Assert.assertArrayEquals(bodyBytes, newBodyBytes);
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) Data(org.apache.qpid.proton.amqp.messaging.Data) Binary(org.apache.qpid.proton.amqp.Binary) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Test(org.junit.Test)

Example 50 with AMQPMessage

use of org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage in project activemq-artemis by apache.

the class JMSMappingInboundTransformerTest method testCreateBytesMessageFromDataWithEmptyBinaryAndContentType.

// ----- Data Body Section ------------------------------------------------//
/**
 * Test that a data body containing nothing, but with the content type set to
 * {@value AMQPMessageSupport#OCTET_STREAM_CONTENT_TYPE} results in a BytesMessage when not
 * otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception
 *         if an error occurs during the test.
 */
@Test
public void testCreateBytesMessageFromDataWithEmptyBinaryAndContentType() throws Exception {
    Message message = Proton.message();
    Binary binary = new Binary(new byte[0]);
    message.setBody(new Data(binary));
    message.setContentType(AMQPMessageSupport.OCTET_STREAM_CONTENT_TYPE);
    javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(new AMQPMessage(message).toCore());
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass());
}
Also used : ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) Message(org.apache.qpid.proton.message.Message) TextMessage(javax.jms.TextMessage) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) Data(org.apache.qpid.proton.amqp.messaging.Data) Binary(org.apache.qpid.proton.amqp.Binary) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Test(org.junit.Test)

Aggregations

AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)57 Test (org.junit.Test)49 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)35 Message (org.apache.qpid.proton.message.Message)26 MessageImpl (org.apache.qpid.proton.message.impl.MessageImpl)21 ServerJMSBytesMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage)20 ServerJMSMapMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage)20 ServerJMSMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage)20 ServerJMSStreamMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage)20 ServerJMSTextMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage)20 TextMessage (javax.jms.TextMessage)19 ServerJMSObjectMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage)19 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)19 Header (org.apache.qpid.proton.amqp.messaging.Header)11 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)10 HashMap (java.util.HashMap)9 Binary (org.apache.qpid.proton.amqp.Binary)9 Data (org.apache.qpid.proton.amqp.messaging.Data)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 ByteBuf (io.netty.buffer.ByteBuf)4