Search in sources :

Example 16 with GetResponse

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

the class QueueSizeLimit method getUnacked.

private List<Long> getUnacked(int howMany) throws IOException {
    List<Long> tags = new ArrayList<Long>(howMany);
    for (; howMany > 0; howMany--) {
        GetResponse response = channel.basicGet(q, false);
        tags.add(response.getEnvelope().getDeliveryTag());
    }
    return tags;
}
Also used : ArrayList(java.util.ArrayList) GetResponse(com.rabbitmq.client.GetResponse)

Example 17 with GetResponse

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

the class TTLHandling method expectBodyAndRemainingMessages.

protected void expectBodyAndRemainingMessages(String body, int messagesLeft) throws IOException {
    GetResponse response = channel.basicGet(TTL_QUEUE_NAME, false);
    assertNotNull(response);
    assertEquals(body, new String(response.getBody()));
    assertEquals(messagesLeft, response.getMessageCount());
}
Also used : GetResponse(com.rabbitmq.client.GetResponse)

Example 18 with GetResponse

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

the class Policies method deadLetterExchangeArgs.

// again the argument takes priority over the policy
@Test
public void deadLetterExchangeArgs() throws IOException, InterruptedException {
    Map<String, Object> args = ttlArgs(0);
    args.put("x-dead-letter-exchange", "dlx2");
    args.put("x-dead-letter-routing-key", "rk2");
    String src = declareQueue("has-dlx-args", args);
    String dest = declareQueue();
    channel.exchangeDeclare("dlx2", "fanout", false, true, null);
    channel.queueBind(dest, "dlx2", "");
    basicPublishVolatile(src);
    Thread.sleep(DELAY);
    GetResponse resp = channel.basicGet(dest, true);
    assertEquals("rk2", resp.getEnvelope().getRoutingKey());
}
Also used : GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 19 with GetResponse

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

the class BindingLifecycle method queuePurge.

/**
 * This tests that when you purge a queue, all of its messages go.
 */
@Test
public void queuePurge() throws IOException {
    Binding binding = setupExchangeBindings(false);
    channel.basicPublish(binding.x, binding.k, null, payload);
    // Purge the queue, and test that we don't receive a message
    channel.queuePurge(binding.q);
    GetResponse response = channel.basicGet(binding.q, true);
    assertNull("The response SHOULD BE null", response);
    deleteExchangeAndQueue(binding);
}
Also used : GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 20 with GetResponse

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

the class BindingLifecycle method unackedPurge.

/**
 * See bug 21854:
 * "When Queue.Purge is called, sent-but-unacknowledged messages are no
 * longer purged, even if the channel they were sent down is not
 * (Tx-)transacted."
 */
@SuppressWarnings("deprecation")
@Test
public void unackedPurge() throws IOException {
    Binding binding = setupExchangeBindings(false);
    channel.basicPublish(binding.x, binding.k, null, payload);
    GetResponse response = channel.basicGet(binding.q, false);
    assertFalse(response.getEnvelope().isRedeliver());
    assertNotNull("The response SHOULD NOT BE null", response);
    // If we purge the queue the unacked message should still be there on
    // recover.
    channel.queuePurge(binding.q);
    response = channel.basicGet(binding.q, true);
    assertNull("The response SHOULD BE null", response);
    channel.basicRecover();
    response = channel.basicGet(binding.q, false);
    channel.basicRecover();
    assertTrue(response.getEnvelope().isRedeliver());
    assertNotNull("The response SHOULD NOT BE null", response);
    // If we recover then purge the message should go away
    channel.queuePurge(binding.q);
    response = channel.basicGet(binding.q, true);
    assertNull("The response SHOULD BE null", response);
    deleteExchangeAndQueue(binding);
}
Also used : 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