Search in sources :

Example 61 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class ClientDefinedMultiConsumerTest method test2ConsumersOnSharedDurableAddressGlobal.

@Test(timeout = 60000)
public void test2ConsumersOnSharedDurableAddressGlobal() throws Exception {
    AddressInfo addressInfo = new AddressInfo(address);
    addressInfo.getRoutingTypes().add(RoutingType.MULTICAST);
    server.addAddressInfo(addressInfo);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect(false));
    AmqpSession session = connection.createSession();
    Source source = createSharedGlobalSource(TerminusDurability.CONFIGURATION);
    AmqpReceiver receiver = session.createMulticastReceiver(source, "myReceiverID", "mySub");
    AmqpReceiver receiver2 = session.createMulticastReceiver(source, "myReceiverID", "mySub|2");
    receiver.flow(1);
    receiver2.flow(1);
    sendMessages(address.toString(), 2);
    AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    amqpMessage = receiver2.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    assertEquals(2, ((QueueImpl) server.getPostOffice().getBinding(SimpleString.toSimpleString("mySub:global")).getBindable()).getConsumerCount());
    receiver.close();
    assertNotNull(server.getPostOffice().getBinding(SimpleString.toSimpleString("mySub:global")));
    receiver2.close();
    // check its been deleted
    assertNull(server.getPostOffice().getBinding(SimpleString.toSimpleString("mySub:global")));
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Source(org.apache.qpid.proton.amqp.messaging.Source) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 62 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class ClientDefinedMultiConsumerTest method test2ConsumersOnSharedDurableAddress.

@Test(timeout = 60000)
public void test2ConsumersOnSharedDurableAddress() throws Exception {
    AddressInfo addressInfo = new AddressInfo(address);
    addressInfo.getRoutingTypes().add(RoutingType.MULTICAST);
    server.addAddressInfo(addressInfo);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect("myClientId"));
    AmqpSession session = connection.createSession();
    Source source = createSharedSource(TerminusDurability.CONFIGURATION);
    AmqpReceiver receiver = session.createMulticastReceiver(source, "myReceiverID", "mySub");
    AmqpReceiver receiver2 = session.createMulticastReceiver(source, "myReceiverID", "mySub|2");
    receiver.flow(1);
    receiver2.flow(1);
    sendMessages(address.toString(), 2);
    AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    amqpMessage = receiver2.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    assertEquals(2, ((QueueImpl) server.getPostOffice().getBinding(SimpleString.toSimpleString("myClientId.mySub")).getBindable()).getConsumerCount());
    receiver.close();
    assertNotNull(server.getPostOffice().getBinding(SimpleString.toSimpleString("myClientId.mySub")));
    receiver2.close();
    // check its been deleted
    assertNull(server.getPostOffice().getBinding(SimpleString.toSimpleString("myClientId.mySub")));
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Source(org.apache.qpid.proton.amqp.messaging.Source) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 63 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpPluginTest method testQueueReceiverReadAndAckMessage.

@Test(timeout = 60000)
public void testQueueReceiverReadAndAckMessage() throws Exception {
    sendMessages(getQueueName(), 1);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    Queue queueView = getProxyToQueue(getQueueName());
    assertEquals(1, queueView.getMessageCount());
    receiver.flow(1);
    AmqpMessage message = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(message);
    message.accept();
    receiver.close();
    connection.close();
    verifier.validatePluginMethodsEquals(0, MESSAGE_EXPIRED, BEFORE_DEPLOY_BRIDGE, AFTER_DEPLOY_BRIDGE, BEFORE_REMOVE_BINDING, AFTER_REMOVE_BINDING);
    verifier.validatePluginMethodsAtLeast(1, AFTER_CREATE_CONNECTION, AFTER_DESTROY_CONNECTION, BEFORE_CREATE_SESSION, AFTER_CREATE_SESSION, BEFORE_CLOSE_SESSION, AFTER_CLOSE_SESSION, BEFORE_CREATE_CONSUMER, AFTER_CREATE_CONSUMER, BEFORE_CLOSE_CONSUMER, AFTER_CLOSE_CONSUMER, BEFORE_CREATE_QUEUE, AFTER_CREATE_QUEUE, MESSAGE_ACKED, BEFORE_SEND, AFTER_SEND, BEFORE_MESSAGE_ROUTE, AFTER_MESSAGE_ROUTE, BEFORE_DELIVER, AFTER_DELIVER, BEFORE_ADD_ADDRESS, AFTER_ADD_ADDRESS, BEFORE_ADD_BINDING, AFTER_ADD_BINDING);
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 64 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpSendReceiveInterceptorTest method testCreateQueueReceiver.

@Test(timeout = 60000)
public void testCreateQueueReceiver() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    server.getRemotingService().addIncomingInterceptor(new AmqpInterceptor() {

        @Override
        public boolean intercept(AMQPMessage message, RemotingConnection connection) throws ActiveMQException {
            latch.countDown();
            return true;
        }
    });
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getTestName());
    AmqpMessage message = new AmqpMessage();
    message.setMessageId("msg" + 1);
    message.setText("Test-Message");
    sender.send(message);
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    final CountDownLatch latch2 = new CountDownLatch(1);
    server.getRemotingService().addOutgoingInterceptor(new AmqpInterceptor() {

        @Override
        public boolean intercept(AMQPMessage packet, RemotingConnection connection) throws ActiveMQException {
            latch2.countDown();
            return true;
        }
    });
    AmqpReceiver receiver = session.createReceiver(getTestName());
    receiver.flow(2);
    AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    assertEquals(latch2.getCount(), 0);
    sender.close();
    receiver.close();
    connection.close();
}
Also used : AmqpInterceptor(org.apache.activemq.artemis.protocol.amqp.broker.AmqpInterceptor) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) CountDownLatch(java.util.concurrent.CountDownLatch) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 65 with AmqpMessage

use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.

the class AmqpSendReceiveInterceptorTest method testCheckInterceptedMessageProperties.

@Test(timeout = 60000)
public void testCheckInterceptedMessageProperties() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final String addressQueue = getTestName();
    final String messageId = "lala200";
    final String correlationId = "lala-corrId";
    final String msgText = "Test intercepted message";
    final boolean durableMsg = false;
    final short priority = 8;
    final long timeToLive = 10000;
    final String replyTo = "reply-to-myQueue";
    Map<String, Object> expectedProperties = new HashMap<>();
    expectedProperties.put(ADDRESS, addressQueue);
    expectedProperties.put(MESSAGE_ID, messageId);
    expectedProperties.put(CORRELATION_ID, correlationId);
    expectedProperties.put(MESSAGE_TEXT, msgText);
    expectedProperties.put(DURABLE, durableMsg);
    expectedProperties.put(PRIORITY, priority);
    expectedProperties.put(REPLY_TO, replyTo);
    expectedProperties.put(TIME_TO_LIVE, timeToLive);
    server.getRemotingService().addIncomingInterceptor(new AmqpInterceptor() {

        @Override
        public boolean intercept(AMQPMessage message, RemotingConnection connection) throws ActiveMQException {
            latch.countDown();
            return checkMessageProperties(message, expectedProperties);
        }
    });
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getTestName());
    AmqpMessage message = new AmqpMessage();
    message.setMessageId(messageId);
    message.setCorrelationId(correlationId);
    message.setText(msgText);
    message.setDurable(durableMsg);
    message.setPriority(priority);
    message.setReplyToAddress(replyTo);
    message.setTimeToLive(timeToLive);
    sender.send(message);
    assertTrue(latch.await(2, TimeUnit.SECONDS));
    final CountDownLatch latch2 = new CountDownLatch(1);
    server.getRemotingService().addOutgoingInterceptor(new AmqpInterceptor() {

        @Override
        public boolean intercept(AMQPMessage packet, RemotingConnection connection) throws ActiveMQException {
            latch2.countDown();
            return checkMessageProperties(packet, expectedProperties);
        }
    });
    AmqpReceiver receiver = session.createReceiver(getTestName());
    receiver.flow(2);
    AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    assertEquals(latch2.getCount(), 0);
    sender.close();
    receiver.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) HashMap(java.util.HashMap) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) CountDownLatch(java.util.concurrent.CountDownLatch) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AmqpInterceptor(org.apache.activemq.artemis.protocol.amqp.broker.AmqpInterceptor) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Test(org.junit.Test)

Aggregations

AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)118 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)115 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)114 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)114 Test (org.junit.Test)100 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)94 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)82 Queue (org.apache.activemq.artemis.core.server.Queue)56 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)16 Source (org.apache.qpid.proton.amqp.messaging.Source)9 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Connection (javax.jms.Connection)4 Message (javax.jms.Message)4 MessageConsumer (javax.jms.MessageConsumer)4 Session (javax.jms.Session)4 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)4 Delivery (org.apache.qpid.proton.engine.Delivery)4