Search in sources :

Example 71 with AmqpReceiver

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

the class AmqpSendReceiveTest method testTwoQueueReceiversOnSameConnectionReadMessagesAcceptOnEach.

@Test(timeout = 60000)
public void testTwoQueueReceiversOnSameConnectionReadMessagesAcceptOnEach() throws Exception {
    int MSG_COUNT = 4;
    sendMessages(getQueueName(), MSG_COUNT);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver1 = session.createReceiver(getQueueName());
    final Queue queueView = getProxyToQueue(getQueueName());
    assertEquals(MSG_COUNT, queueView.getMessageCount());
    receiver1.flow(2);
    AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
    assertNotNull(message);
    message.accept();
    message = receiver1.receive(5, TimeUnit.SECONDS);
    assertNotNull(message);
    message.accept();
    assertTrue("Should have ack'd two", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisfied() throws Exception {
            return queueView.getMessagesAcknowledged() == 2;
        }
    }, TimeUnit.SECONDS.toMillis(5), TimeUnit.MILLISECONDS.toMillis(50)));
    AmqpReceiver receiver2 = session.createReceiver(getQueueName());
    assertEquals(2, server.getTotalConsumerCount());
    receiver2.flow(2);
    message = receiver2.receive(5, TimeUnit.SECONDS);
    assertNotNull(message);
    message.accept();
    message = receiver2.receive(5, TimeUnit.SECONDS);
    assertNotNull(message);
    message.accept();
    assertTrue("Queue should be empty now", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisfied() throws Exception {
            return queueView.getMessagesAcknowledged() == 4;
        }
    }, TimeUnit.SECONDS.toMillis(15), TimeUnit.MILLISECONDS.toMillis(10)));
    receiver1.close();
    receiver2.close();
    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) 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 72 with AmqpReceiver

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

the class AmqpSessionTest method testSessionClosedDoesNotGetReceiverDetachFromRemote.

@Test(timeout = 60000)
public void testSessionClosedDoesNotGetReceiverDetachFromRemote() throws Exception {
    AmqpClient client = createAmqpClient();
    assertNotNull(client);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectClosedResource(Session session) {
            IntegrationTestLogger.LOGGER.info("Session closed: " + session.getContext());
        }

        @Override
        public void inspectDetachedResource(Receiver receiver) {
            markAsInvalid("Broker should not detach receiver linked to closed session.");
        }

        @Override
        public void inspectClosedResource(Receiver receiver) {
            markAsInvalid("Broker should not close receiver linked to closed session.");
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    assertNotNull(connection);
    AmqpSession session = connection.createSession();
    assertNotNull(session);
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    assertNotNull(receiver);
    session.close();
    connection.getStateInspector().assertValid();
    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) Receiver(org.apache.qpid.proton.engine.Receiver) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Session(org.apache.qpid.proton.engine.Session) Test(org.junit.Test)

Example 73 with AmqpReceiver

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

the class AmqpTempDestinationTest method doTestCreateDynamicSenderAndPublish.

protected void doTestCreateDynamicSenderAndPublish(boolean topic) throws Exception {
    Target target = createDynamicTarget(topic);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(target);
    assertNotNull(sender);
    Target remoteTarget = (Target) sender.getEndpoint().getRemoteTarget();
    Queue queueView = getProxyToQueue(remoteTarget.getAddress());
    assertNotNull(queueView);
    // Get the new address
    String address = sender.getSender().getRemoteTarget().getAddress();
    LOG.info("New dynamic sender address -> {}", address);
    // Create a message and send to a receive that is listening on the newly
    // created dynamic link address.
    AmqpMessage message = new AmqpMessage();
    message.setMessageId("msg-1");
    message.setText("Test-Message");
    AmqpReceiver receiver = session.createReceiver(address);
    receiver.flow(1);
    sender.send(message);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull("Should have read a message", received);
    received.accept();
    receiver.close();
    sender.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Target(org.apache.qpid.proton.amqp.messaging.Target) 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)

Example 74 with AmqpReceiver

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

the class AmqpTempDestinationTest method doTestCreateDynamicReceiverAndSend.

protected void doTestCreateDynamicReceiverAndSend(boolean topic) throws Exception {
    Source source = createDynamicSource(topic);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(source);
    assertNotNull(receiver);
    Source remoteSource = (Source) receiver.getEndpoint().getRemoteSource();
    Queue queueView = getProxyToQueue(remoteSource.getAddress());
    assertNotNull(queueView);
    // Get the new address
    String address = receiver.getReceiver().getRemoteSource().getAddress();
    LOG.info("New dynamic receiver address -> {}", address);
    // Create a message and send to a receive that is listening on the newly
    // created dynamic link address.
    AmqpMessage message = new AmqpMessage();
    message.setMessageId("msg-1");
    message.setText("Test-Message");
    AmqpSender sender = session.createSender(address);
    sender.send(message);
    receiver.flow(1);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull("Should have read a message", received);
    received.accept();
    sender.close();
    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) Queue(org.apache.activemq.artemis.core.server.Queue) Source(org.apache.qpid.proton.amqp.messaging.Source) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage)

Example 75 with AmqpReceiver

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

the class AmqpTransactionTest method testReceiveAfterConnectionClose.

@Test(timeout = 60000)
public void testReceiveAfterConnectionClose() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    final Queue queue = getProxyToQueue(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setText("Test-Message");
    sender.send(message);
    Wait.assertEquals(1, queue::getMessageCount);
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    session.begin();
    receiver.flow(1);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(received);
    received.accept();
    // this will force a rollback on the TX (It should at least)
    connection.close();
    connection = addConnection(client.connect());
    session = connection.createSession();
    receiver = session.createReceiver(getQueueName());
    session.begin();
    receiver.flow(1);
    received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(received);
    received.accept();
    session.commit();
    assertEquals(0, queue.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) 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)

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