Search in sources :

Example 66 with AmqpSender

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

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

Example 68 with AmqpSender

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

the class AmqpTransactionTest method testMultipleSessionSendersInSingleTXNWithRollback.

@Test(timeout = 60000)
public void testMultipleSessionSendersInSingleTXNWithRollback() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    // Root TXN session controls all TXN send lifetimes.
    AmqpSession txnSession = connection.createSession();
    // Create some sender sessions
    AmqpSession session1 = connection.createSession();
    AmqpSession session2 = connection.createSession();
    AmqpSession session3 = connection.createSession();
    // Sender linked to each session
    AmqpSender sender1 = session1.createSender(getQueueName());
    AmqpSender sender2 = session2.createSender(getQueueName());
    AmqpSender sender3 = session3.createSender(getQueueName());
    final Queue queue = getProxyToQueue(getQueueName());
    assertEquals(0, queue.getMessageCount());
    // Begin the transaction that all senders will operate in.
    txnSession.begin();
    AmqpMessage message = new AmqpMessage();
    message.setText("Test-Message");
    assertTrue(txnSession.isInTransaction());
    sender1.send(message, txnSession.getTransactionId());
    sender2.send(message, txnSession.getTransactionId());
    sender3.send(message, txnSession.getTransactionId());
    assertEquals(0, queue.getMessageCount());
    txnSession.rollback();
    assertEquals(0, queue.getMessageCount());
}
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 69 with AmqpSender

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

the class AmqpTransactionTest method testReceiveMessageWithRollback.

@Test(timeout = 60000)
public void testReceiveMessageWithRollback() 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();
    session.rollback();
    assertEquals(1, queue.getMessageCount());
    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 70 with AmqpSender

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

the class AmqpTransactionTest method testMultipleSessionReceiversInSingleTXNWithRollback.

@Test(timeout = 60000)
public void testMultipleSessionReceiversInSingleTXNWithRollback() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    // Load up the Queue with some messages
    {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(getQueueName());
        AmqpMessage message = new AmqpMessage();
        message.setText("Test-Message");
        sender.send(message);
        sender.send(message);
        sender.send(message);
        sender.close();
    }
    // Root TXN session controls all TXN send lifetimes.
    AmqpSession txnSession = connection.createSession();
    // Create some sender sessions
    AmqpSession session1 = connection.createSession();
    AmqpSession session2 = connection.createSession();
    AmqpSession session3 = connection.createSession();
    // Sender linked to each session
    AmqpReceiver receiver1 = session1.createReceiver(getQueueName());
    AmqpReceiver receiver2 = session2.createReceiver(getQueueName());
    AmqpReceiver receiver3 = session3.createReceiver(getQueueName());
    final Queue queue = getProxyToQueue(getQueueName());
    assertEquals(3, queue.getMessageCount());
    // Begin the transaction that all senders will operate in.
    txnSession.begin();
    assertTrue(txnSession.isInTransaction());
    receiver1.flow(1);
    receiver2.flow(1);
    receiver3.flow(1);
    AmqpMessage message1 = receiver1.receive(5, TimeUnit.SECONDS);
    AmqpMessage message2 = receiver2.receive(5, TimeUnit.SECONDS);
    AmqpMessage message3 = receiver3.receive(5, TimeUnit.SECONDS);
    message1.accept(txnSession);
    message2.accept(txnSession);
    message3.accept(txnSession);
    assertEquals(3, queue.getMessageCount());
    txnSession.rollback();
    assertEquals(3, queue.getMessageCount());
}
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

AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)90 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)90 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)89 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)89 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)82 Test (org.junit.Test)74 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)61 Queue (org.apache.activemq.artemis.core.server.Queue)47 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 URI (java.net.URI)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)5 Sender (org.apache.qpid.proton.engine.Sender)5 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 Delivery (org.apache.qpid.proton.engine.Delivery)4 BytesMessage (javax.jms.BytesMessage)3