Search in sources :

Example 41 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.

the class RequeueOnClose method publishAndGet.

private void publishAndGet(int count, boolean doAck) throws IOException, InterruptedException, TimeoutException {
    openConnection();
    for (int repeat = 0; repeat < count; repeat++) {
        open();
        injectMessage();
        GetResponse r1 = getMessage();
        if (doAck)
            channel.basicAck(r1.getEnvelope().getDeliveryTag(), false);
        close();
        open();
        if (doAck) {
            assertNull("Expected missing second basicGet (repeat=" + repeat + ")", getMessage());
        } else {
            assertNotNull("Expected present second basicGet (repeat=" + repeat + ")", getMessage());
        }
        close();
    }
    closeConnection();
}
Also used : GetResponse(com.rabbitmq.client.GetResponse)

Example 42 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.

the class Policies method deadLetterExchange.

@Test
public void deadLetterExchange() throws IOException, InterruptedException {
    Map<String, Object> args = ttlArgs(0);
    String src = declareQueue("has-dlx", args);
    String dest = declareQueue();
    channel.exchangeDeclare("dlx", "fanout", false, true, null);
    channel.queueBind(dest, "dlx", "");
    basicPublishVolatile(src);
    Thread.sleep(DELAY);
    GetResponse resp = channel.basicGet(dest, true);
    assertEquals("rk", resp.getEnvelope().getRoutingKey());
    clearPolicies();
    basicPublishVolatile(src);
    Thread.sleep(DELAY);
    assertDelivered(dest, 0);
}
Also used : GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 43 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.

the class BindingLifecycleBase method sendUnroutable.

protected void sendUnroutable(Binding binding) throws IOException {
    channel.basicPublish(binding.x, binding.k, null, payload);
    GetResponse response = channel.basicGet(binding.q, true);
    assertNull("The response SHOULD BE null", response);
}
Also used : GetResponse(com.rabbitmq.client.GetResponse)

Example 44 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.

the class BindingLifecycleBase method sendRoutable.

protected void sendRoutable(Binding binding) throws IOException {
    channel.basicPublish(binding.x, binding.k, null, payload);
    GetResponse response = channel.basicGet(binding.q, true);
    assertNotNull("The response should not be null", response);
}
Also used : GetResponse(com.rabbitmq.client.GetResponse)

Example 45 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.

the class Metrics method metricsAck.

@Test
public void metricsAck() throws IOException, TimeoutException {
    StandardMetricsCollector metrics = new StandardMetricsCollector();
    connectionFactory.setMetricsCollector(metrics);
    Connection connection = null;
    try {
        connection = connectionFactory.newConnection();
        Channel channel1 = connection.createChannel();
        Channel channel2 = connection.createChannel();
        sendMessage(channel1);
        GetResponse getResponse = channel1.basicGet(QUEUE, false);
        channel1.basicAck(getResponse.getEnvelope().getDeliveryTag(), false);
        assertThat(metrics.getConsumedMessages().getCount()).isEqualTo(1L);
        assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L);
        // basicGet / basicAck
        sendMessage(channel1);
        sendMessage(channel2);
        sendMessage(channel1);
        sendMessage(channel2);
        sendMessage(channel1);
        sendMessage(channel2);
        GetResponse response1 = channel1.basicGet(QUEUE, false);
        GetResponse response2 = channel2.basicGet(QUEUE, false);
        GetResponse response3 = channel1.basicGet(QUEUE, false);
        GetResponse response4 = channel2.basicGet(QUEUE, false);
        GetResponse response5 = channel1.basicGet(QUEUE, false);
        GetResponse response6 = channel2.basicGet(QUEUE, false);
        assertThat(metrics.getConsumedMessages().getCount()).isEqualTo(1L + 6L);
        assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L);
        channel1.basicAck(response5.getEnvelope().getDeliveryTag(), false);
        assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L + 1L);
        channel1.basicAck(response3.getEnvelope().getDeliveryTag(), true);
        assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L + 1L + 2L);
        channel2.basicAck(response2.getEnvelope().getDeliveryTag(), true);
        assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L + (1L + 2L) + 1L);
        channel2.basicAck(response6.getEnvelope().getDeliveryTag(), true);
        assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L + (1L + 2L) + 1L + 2L);
        long alreadySentMessages = 1 + (1 + 2) + 1 + 2;
        // basicConsume / basicAck
        channel1.basicConsume(QUEUE, false, new MultipleAckConsumer(channel1, false));
        channel1.basicConsume(QUEUE, false, new MultipleAckConsumer(channel1, true));
        channel2.basicConsume(QUEUE, false, new MultipleAckConsumer(channel2, false));
        channel2.basicConsume(QUEUE, false, new MultipleAckConsumer(channel2, true));
        int nbMessages = 10;
        for (int i = 0; i < nbMessages; i++) {
            sendMessage(i % 2 == 0 ? channel1 : channel2);
        }
        waitAtMost(timeout(), () -> metrics.getConsumedMessages().getCount() == alreadySentMessages + nbMessages);
        waitAtMost(timeout(), () -> metrics.getAcknowledgedMessages().getCount() == alreadySentMessages + nbMessages);
    } finally {
        safeClose(connection);
    }
}
Also used : StandardMetricsCollector(com.rabbitmq.client.impl.StandardMetricsCollector) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) AutorecoveringConnection(com.rabbitmq.client.impl.recovery.AutorecoveringConnection) GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Aggregations

GetResponse (com.rabbitmq.client.GetResponse)55 Test (org.junit.Test)27 Channel (com.rabbitmq.client.Channel)10 IOException (java.io.IOException)10 Envelope (com.rabbitmq.client.Envelope)8 Connection (com.rabbitmq.client.Connection)7 Message (de.gessnerfl.rabbitmq.queue.management.model.Message)6 HashMap (java.util.HashMap)6 AMQP (com.rabbitmq.client.AMQP)5 LongString (com.rabbitmq.client.LongString)5 BasicProperties (com.rabbitmq.client.AMQP.BasicProperties)4 BasicProperties (de.gessnerfl.rabbitmq.queue.management.model.BasicProperties)4 RMQDestination (com.rabbitmq.jms.admin.RMQDestination)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Queue (javax.jms.Queue)3 QueueSender (javax.jms.QueueSender)3 QueueSession (javax.jms.QueueSession)3