Search in sources :

Example 61 with AmqpReceiver

use of org.apache.activemq.transport.amqp.client.AmqpReceiver 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 62 with AmqpReceiver

use of org.apache.activemq.transport.amqp.client.AmqpReceiver 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)

Example 63 with AmqpReceiver

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

the class AmqpSendReceiveTest method testMessageDurabliltyFollowsSpec.

@Test(timeout = 60000)
public void testMessageDurabliltyFollowsSpec() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    AmqpReceiver receiver1 = session.createReceiver(getQueueName());
    Queue queue = getProxyToQueue(getQueueName());
    // Create default message that should be sent as non-durable
    AmqpMessage message1 = new AmqpMessage();
    message1.setText("Test-Message -> non-durable");
    message1.setDurable(false);
    message1.setMessageId("ID:Message:1");
    sender.send(message1);
    Wait.assertEquals(1, queue::getMessageCount);
    receiver1.flow(1);
    message1 = receiver1.receive(50, TimeUnit.SECONDS);
    assertNotNull("Should have read a message", message1);
    assertFalse("First message sent should not be durable", message1.isDurable());
    message1.accept();
    // Create default message that should be sent as durable
    AmqpMessage message2 = new AmqpMessage();
    message2.setText("Test-Message -> durable");
    message2.setDurable(true);
    message2.setMessageId("ID:Message:2");
    sender.send(message2);
    Wait.assertEquals(1, queue::getMessageCount);
    receiver1.flow(1);
    message2 = receiver1.receive(50, TimeUnit.SECONDS);
    assertNotNull("Should have read a message", message2);
    assertTrue("Second message sent should be durable", message2.isDurable());
    message2.accept();
    sender.close();
    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) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 64 with AmqpReceiver

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

the class AmqpSendReceiveTest method testCoreBridge.

@Test(timeout = 60000)
public void testCoreBridge() throws Exception {
    server.getRemotingService().createAcceptor("acceptor", "vm://0").start();
    server.getConfiguration().addConnectorConfiguration("connector", "vm://0");
    server.deployBridge(new BridgeConfiguration().setName(getTestName()).setQueueName(getQueueName()).setForwardingAddress(getQueueName(1)).setConfirmationWindowSize(10).setStaticConnectors(Arrays.asList("connector")));
    sendMessages(getQueueName(), 1);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(getQueueName(1));
    Queue queueView = getProxyToQueue(getQueueName());
    Wait.assertEquals(1, queueView::getConsumerCount);
    Wait.assertEquals(0, queueView::getMessageCount);
    queueView = getProxyToQueue(getQueueName(1));
    Wait.assertEquals(1, queueView::getConsumerCount);
    Wait.assertEquals(1, queueView::getMessageCount);
    receiver.flow(1);
    AmqpMessage message = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(message);
    message.accept();
    receiver.close();
    Wait.assertEquals(0, queueView::getMessageCount);
    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) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) 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 65 with AmqpReceiver

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

the class AmqpSendReceiveTest method testReceiveWithJMSSelectorFilterOnJMSType.

@Test(timeout = 60000)
public void testReceiveWithJMSSelectorFilterOnJMSType() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpMessage message1 = new AmqpMessage();
    message1.setText("msg:1");
    AmqpMessage message2 = new AmqpMessage();
    message2.setSubject("target");
    message2.setText("msg:2");
    AmqpSender sender = session.createSender(getQueueName());
    sender.send(message1);
    sender.send(message2);
    sender.close();
    AmqpReceiver receiver = session.createReceiver(getQueueName(), "JMSType = 'target'");
    receiver.flow(2);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull("Should have read a message", received);
    assertEquals("target", received.getSubject());
    received.accept();
    assertNull(receiver.receive(1, TimeUnit.SECONDS));
    receiver.close();
    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) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Aggregations

AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)118 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)118 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)118 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)118 Test (org.junit.Test)101 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)94 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)61 Queue (org.apache.activemq.artemis.core.server.Queue)59 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)17 Source (org.apache.qpid.proton.amqp.messaging.Source)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)12 Receiver (org.apache.qpid.proton.engine.Receiver)6 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)3 Wait (org.apache.activemq.artemis.tests.util.Wait)3 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)3 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2