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();
}
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();
}
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());
}
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();
}
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());
}
Aggregations