use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class AmqpReceiverWithFiltersTest method testReceivedUnsignedFilter.
@Test(timeout = 60000)
public void testReceivedUnsignedFilter() throws Exception {
final int NUM_MESSAGES = 100;
AmqpClient client = createAmqpClient();
AmqpConnection connection = client.connect();
try {
// Normal Session which won't create an TXN itself
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName());
for (int i = 0; i < NUM_MESSAGES + 1; ++i) {
AmqpMessage message = new AmqpMessage();
message.setText("Test-Message");
message.setApplicationProperty("myNewID", new UnsignedInteger(i));
sender.send(message);
}
// Read all messages from the Queue, do not accept them yet.
AmqpReceiver receiver = session.createReceiver(getQueueName(), "myNewID < " + (NUM_MESSAGES / 2));
ArrayList<AmqpMessage> messages = new ArrayList<>(NUM_MESSAGES);
receiver.flow((NUM_MESSAGES + 2) * 2);
for (int i = 0; i < NUM_MESSAGES / 2; ++i) {
AmqpMessage message = receiver.receive(5, TimeUnit.SECONDS);
Assert.assertNotNull(message);
System.out.println("Read message: " + message.getApplicationProperty("myNewID"));
assertNotNull(message);
messages.add(message);
}
Assert.assertNull(receiver.receiveNoWait());
} finally {
connection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class AmqpScheduledMessageTest method testSendWithDeliveryTimeHoldsMessage.
@Test(timeout = 60000)
public void testSendWithDeliveryTimeHoldsMessage() throws Exception {
AmqpClient client = createAmqpClient();
assertNotNull(client);
AmqpConnection connection = addConnection(client.connect());
try {
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName());
AmqpReceiver receiver = session.createReceiver(getQueueName());
AmqpMessage message = new AmqpMessage();
long deliveryTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5);
message.setMessageAnnotation("x-opt-delivery-time", deliveryTime);
message.setText("Test-Message");
sender.send(message);
// Now try and get the message
receiver.flow(1);
// Shouldn't get this since we delayed the message.
assertNull(receiver.receive(1, TimeUnit.SECONDS));
} finally {
connection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class BrokerDefinedAnycastConsumerTest method testConsumeFromSingleQueueOnAddressDifferentNameMultipleQueues.
@Test(timeout = 60000)
public void testConsumeFromSingleQueueOnAddressDifferentNameMultipleQueues() throws Exception {
server.addAddressInfo(new AddressInfo(address, RoutingType.ANYCAST));
server.createQueue(address, RoutingType.ANYCAST, queue1, null, true, false);
server.createQueue(address, RoutingType.ANYCAST, queue2, null, true, false);
sendMessages(address.toString(), 1);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpReceiver receiver = session.createReceiver(address.toString());
receiver.flow(1);
AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(amqpMessage);
assertEquals(1, ((QueueImpl) server.getPostOffice().getBinding(queue1).getBindable()).getConsumerCount());
assertEquals(0, ((QueueImpl) server.getPostOffice().getBinding(queue2).getBindable()).getConsumerCount());
receiver.close();
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class BrokerDefinedAnycastConsumerTest method testConsumeFromSingleQueueOnAddressSameName.
@Test(timeout = 60000)
public void testConsumeFromSingleQueueOnAddressSameName() throws Exception {
server.addAddressInfo(new AddressInfo(address, RoutingType.ANYCAST));
server.createQueue(address, RoutingType.ANYCAST, address, null, true, false);
sendMessages(address.toString(), 1);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpReceiver receiver = session.createReceiver(address.toString());
receiver.flow(1);
AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(amqpMessage);
assertEquals(1, ((QueueImpl) server.getPostOffice().getBinding(address).getBindable()).getConsumerCount());
receiver.close();
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.
the class BrokerDefinedMulticastConsumerTest method testConsumeFromSingleQueueOnAddressSameName.
@Test(timeout = 60000)
public void testConsumeFromSingleQueueOnAddressSameName() throws Exception {
server.addAddressInfo(new AddressInfo(address, RoutingType.MULTICAST));
server.createQueue(address, RoutingType.MULTICAST, address, null, true, false);
sendMessages(address.toString(), 1);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpReceiver receiver = session.createReceiver(address.toString() + "::" + address.toString());
receiver.flow(1);
AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(amqpMessage);
assertEquals(1, ((QueueImpl) server.getPostOffice().getBinding(address).getBindable()).getConsumerCount());
receiver.close();
connection.close();
}
Aggregations