Search in sources :

Example 1 with ReturnListener

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);
        }
    });
}
Also used : ReturnListener(com.rabbitmq.client.ReturnListener) AMQP(com.rabbitmq.client.AMQP) IOException(java.io.IOException)

Example 2 with ReturnListener

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();
}
Also used : ReturnListener(com.rabbitmq.client.ReturnListener) HashMap(java.util.HashMap) BasicProperties(com.rabbitmq.client.AMQP.BasicProperties) MockComponentLog(org.apache.nifi.util.MockComponentLog) Connection(com.rabbitmq.client.Connection) List(java.util.List) Test(org.junit.Test)

Example 3 with ReturnListener

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;
}
Also used : ReturnListener(com.rabbitmq.client.ReturnListener) Random(java.util.Random) AMQP(com.rabbitmq.client.AMQP) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

ReturnListener (com.rabbitmq.client.ReturnListener)3 AMQP (com.rabbitmq.client.AMQP)2 IOException (java.io.IOException)2 BasicProperties (com.rabbitmq.client.AMQP.BasicProperties)1 Connection (com.rabbitmq.client.Connection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MockComponentLog (org.apache.nifi.util.MockComponentLog)1 Test (org.junit.Test)1