Search in sources :

Example 76 with AmqpMessage

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

the class AmqpSenderTest method testUnsettledSender.

@Test(timeout = 60000)
public void testUnsettledSender() throws Exception {
    final int MSG_COUNT = 1000;
    final CountDownLatch settled = new CountDownLatch(MSG_COUNT);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    connection.setStateInspector(new AmqpValidator() {

        @Override
        public void inspectDeliveryUpdate(Sender sender, Delivery delivery) {
            if (delivery.remotelySettled()) {
                IntegrationTestLogger.LOGGER.trace("Remote settled message for sender: " + sender.getName());
                settled.countDown();
            }
        }
    });
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName(), false);
    for (int i = 1; i <= MSG_COUNT; ++i) {
        AmqpMessage message = new AmqpMessage();
        message.setText("Test-Message: " + i);
        sender.send(message);
        if (i % 1000 == 0) {
            IntegrationTestLogger.LOGGER.info("Sent message: " + i);
        }
    }
    Queue queueView = getProxyToQueue(getQueueName());
    Wait.assertTrue("All messages should arrive", () -> queueView.getMessageCount() == MSG_COUNT);
    sender.close();
    assertTrue("Remote should have settled all deliveries", settled.await(5, TimeUnit.MINUTES));
    connection.close();
}
Also used : AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Delivery(org.apache.qpid.proton.engine.Delivery) CountDownLatch(java.util.concurrent.CountDownLatch) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 77 with AmqpMessage

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

the class AmqpSenderTest method testPresettledSender.

@Test(timeout = 60000)
public void testPresettledSender() throws Exception {
    final int MSG_COUNT = 1000;
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName(), true);
    for (int i = 1; i <= MSG_COUNT; ++i) {
        AmqpMessage message = new AmqpMessage();
        message.setText("Test-Message: " + i);
        sender.send(message);
        if (i % 1000 == 0) {
            IntegrationTestLogger.LOGGER.info("Sent message: " + i);
        }
    }
    Queue queueView = getProxyToQueue(getQueueName());
    Wait.assertTrue("All messages should arrive", () -> queueView.getMessageCount() == MSG_COUNT);
    sender.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) 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 78 with AmqpMessage

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

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

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

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