use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class AmqpSendReceiveTest method testMessageDurableFalse.
@Test(timeout = 60000)
public void testMessageDurableFalse() throws Exception {
sendMessages(getQueueName(), 1, false);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpReceiver receiver = session.createReceiver(getQueueName());
Queue queueView = getProxyToQueue(getQueueName());
assertEquals(1, queueView.getMessageCount());
receiver.flow(1);
AmqpMessage receive = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(receive);
assertFalse(receive.isDurable());
receiver.close();
assertEquals(1, queueView.getMessageCount());
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class AmqpSendReceiveTest method doTestSendReceiveLotsOfDurableMessages.
private void doTestSendReceiveLotsOfDurableMessages(Class<?> destType) throws Exception {
final int MSG_COUNT = 1000;
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
final CountDownLatch done = new CountDownLatch(MSG_COUNT);
final AtomicBoolean error = new AtomicBoolean(false);
final ExecutorService executor = Executors.newSingleThreadExecutor();
final String address;
if (Queue.class.equals(destType)) {
address = getQueueName();
} else {
address = getTopicName();
}
final AmqpReceiver receiver = session.createReceiver(address);
receiver.flow(MSG_COUNT);
AmqpSender sender = session.createSender(address);
Queue queueView = getProxyToQueue(address);
executor.execute(new Runnable() {
@Override
public void run() {
for (int i = 0; i < MSG_COUNT; i++) {
try {
AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
received.accept();
done.countDown();
} catch (Exception ex) {
LOG.info("Caught error: {}", ex.getClass().getSimpleName());
error.set(true);
}
}
}
});
for (int i = 0; i < MSG_COUNT; i++) {
AmqpMessage message = new AmqpMessage();
message.setMessageId("msg" + i);
sender.send(message);
}
assertTrue("did not read all messages, waiting on: " + done.getCount(), done.await(10, TimeUnit.SECONDS));
assertFalse("should not be any errors on receive", error.get());
Wait.assertEquals(0, queueView::getDeliveringCount);
sender.close();
receiver.close();
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class AmqpSendReceiveTest method testTwoQueueReceiversOnSameConnectionReadMessagesNoDispositions.
@Test(timeout = 60000)
public void testTwoQueueReceiversOnSameConnectionReadMessagesNoDispositions() 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());
Queue queueView = getProxyToQueue(getQueueName());
assertEquals(MSG_COUNT, queueView.getMessageCount());
receiver1.flow(2);
assertNotNull(receiver1.receive(5, TimeUnit.SECONDS));
assertNotNull(receiver1.receive(5, TimeUnit.SECONDS));
AmqpReceiver receiver2 = session.createReceiver(getQueueName());
assertEquals(2, server.getTotalConsumerCount());
receiver2.flow(2);
assertNotNull(receiver2.receive(5, TimeUnit.SECONDS));
assertNotNull(receiver2.receive(5, TimeUnit.SECONDS));
assertEquals(0, queueView.getMessagesAcknowledged());
receiver1.close();
receiver2.close();
assertEquals(MSG_COUNT, queueView.getMessageCount());
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class AmqpSendReceiveTest method doTestMessageWithToFieldSet.
private void doTestMessageWithToFieldSet(boolean anonymous, String expected) throws Exception {
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
final String address = getQueueName();
AmqpSender sender = session.createSender(anonymous ? null : address);
AmqpMessage message = new AmqpMessage();
message.setAddress(expected);
message.setMessageId("msg:1");
sender.send(message);
AmqpReceiver receiver = session.createReceiver(address);
Queue queueView = getProxyToQueue(address);
assertEquals(1, queueView.getMessageCount());
receiver.flow(1);
AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(received);
assertEquals(expected, received.getAddress());
receiver.close();
assertEquals(1, queueView.getMessageCount());
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class AmqpTempDestinationTest method doTestDynamicReceiverLifetimeBoundToLinkQueue.
protected void doTestDynamicReceiverLifetimeBoundToLinkQueue(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);
receiver.close();
queueView = getProxyToQueue(remoteSource.getAddress());
assertNull(queueView);
connection.close();
}
Aggregations