use of com.rabbitmq.client.ReturnListener in project rabbitmq-java-client by rabbitmq.
the class AlternateExchange method setUp.
@Override
public void setUp() throws IOException, TimeoutException {
super.setUp();
channel.addReturnListener(new ReturnListener() {
public void handleReturn(int replyCode, String replyText, String exchange, String routingKey, AMQP.BasicProperties properties, byte[] body) throws IOException {
gotReturn.set(true);
}
});
}
use of com.rabbitmq.client.ReturnListener in project nifi by apache.
the class AMQPPublisherTest method validateSuccessfullPublishingAndUndeliverableRoutingKey.
@Test
public void validateSuccessfullPublishingAndUndeliverableRoutingKey() throws Exception {
Map<String, List<String>> routingMap = new HashMap<>();
routingMap.put("key1", Arrays.asList("queue1", "queue2"));
Map<String, String> exchangeToRoutingKeymap = new HashMap<>();
exchangeToRoutingKeymap.put("myExchange", "key1");
Connection connection = new TestConnection(exchangeToRoutingKeymap, routingMap);
ReturnListener retListener = mock(ReturnListener.class);
connection.createChannel().addReturnListener(retListener);
try (AMQPPublisher sender = new AMQPPublisher(connection, new MockComponentLog("foo", ""))) {
sender.publish("hello".getBytes(), null, "key1", "myExchange");
}
verify(retListener, atMost(1)).handleReturn(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(BasicProperties.class), (byte[]) Mockito.any());
connection.close();
}
use of com.rabbitmq.client.ReturnListener in project rabbitmq-java-client by rabbitmq.
the class ScalabilityTest method timeRouting.
private float timeRouting(Channel channel, String[] routingKeys) throws IOException, InterruptedException {
boolean mandatory = true;
boolean immdediate = true;
final CountDownLatch latch = new CountDownLatch(params.messageCount);
channel.addReturnListener(new ReturnListener() {
public void handleReturn(int replyCode, String replyText, String exchange, String routingKey, AMQP.BasicProperties properties, byte[] body) throws IOException {
latch.countDown();
}
});
final long start = System.nanoTime();
// route some messages
Random r = new Random();
int size = routingKeys.length;
for (int n = 0; n < params.messageCount; n++) {
String key = routingKeys[r.nextInt(size)];
channel.basicPublish("amq.direct", key, true, false, MessageProperties.MINIMAL_BASIC, null);
}
// wait for the returns to come back
latch.await();
// Compute the roundtrip time
final long finish = System.nanoTime();
final long wallclock = finish - start;
return (params.messageCount == 0) ? (float) 0.0 : wallclock / (float) params.messageCount / 1000;
}
Aggregations