Package com.rabbitmq.client

Examples of com.rabbitmq.client.GetResponse


  public Message receive(final String queueName) {
    return execute(new ChannelCallback<Message>() {

      @Override
      public Message doInRabbit(Channel channel) throws IOException {
        GetResponse response = channel.basicGet(queueName,
            !isChannelTransacted());
        // Response can be null is the case that there is no message on
        // the queue.
        if (response != null) {
          long deliveryTag = response.getEnvelope().getDeliveryTag();
          if (isChannelLocallyTransacted(channel)) {
            channel.basicAck(deliveryTag, false);
            channel.txCommit();
          } else if (isChannelTransacted()) {
            // Not locally transacted but it is transacted so it
View Full Code Here


      @Override
      public Boolean doInRabbit(Channel channel) throws Exception {
        boolean channelTransacted = RabbitTemplate.this
            .isChannelTransacted();

        GetResponse response = channel.basicGet(queueName,
            !channelTransacted);
        // Response can be null in the case that there is no message on
        // the queue.
        if (response != null) {
          long deliveryTag = response.getEnvelope().getDeliveryTag();
          boolean channelLocallyTransacted = RabbitTemplate.this
              .isChannelLocallyTransacted(channel);

          if (channelLocallyTransacted) {
            channel.basicAck(deliveryTag, false);
View Full Code Here

  protected void assertDelivered(String q, int count) throws IOException {
    assertDelivered(q, count, false);
  }

  protected void assertDelivered(String q, int count, boolean redelivered) throws IOException {
    GetResponse r;
    for (int i = 0; i < count; i++) {
      r = basicGet(q);
      assertNotNull(r);
      assertEquals(r.getEnvelope().isRedeliver(), redelivered);
    }
    assertNull(basicGet(q));
  }
View Full Code Here

        int remaining = batchSize;
        int count = 0;

        while (notEmpty && (remaining > 0)) {
            for (int i = 0; (i < 2) && (remaining > 0); i++) {
                GetResponse c = _ch1.basicGet(queueName, autoAck);
                if (c == null) {
                    notEmpty = false;
                } else {
                    String msg = new String(c.getBody());
                    log("Got message (" + c.getMessageCount() + " left in q): " + msg);
                    latestTag = c.getEnvelope().getDeliveryTag();
                    remaining--;
                    count++;
                }
            }
            if (!autoAck && latestTag != 0) {
View Full Code Here

        Channel channel = connection.createChannel();

        String queue = "ttl.queue";

        // exchange
        GetResponse response = channel.basicGet(queue, false);
        if(response == null) {
            System.out.println("Got no message...");
        } else {
            System.out.println("Got message: " + new String(response.getBody()));
            channel.basicAck(response.getEnvelope().getDeliveryTag(), false);
        }
        channel.close();
        connection.close();
    }
View Full Code Here

        int howMuch = 2*FRAME_MAX;
        basicPublishVolatile(new byte[howMuch], queueName);
        /* Receive everything that was sent out. */
        while (howMuch > 0) {
            try {
                GetResponse response = channel.basicGet(queueName, false);
                howMuch -= response.getBody().length;
            } catch (Exception e) {
                e.printStackTrace();
                fail("Exception in basicGet loop: " + e);
            }
        }
View Full Code Here

    public void rejectionTest(final boolean useNack) throws Exception {
        deadLetterTest(new Callable<Void>() {
                public Void call() throws Exception {
                    for (int x = 0; x < MSG_COUNT; x++) {
                        GetResponse getResponse =
                            channel.basicGet(TEST_QUEUE_NAME, false);
                        long tag = getResponse.getEnvelope().getDeliveryTag();
                        if (useNack) {
                            channel.basicNack(tag, false, false);
                        } else {
                            channel.basicReject(tag, false);
                        }
View Full Code Here

    private void consumeN(String queue, int n, WithResponse withResponse)
        throws IOException
    {
        for(int x = 0; x < n; x++) {
            GetResponse getResponse =
                channel.basicGet(queue, true);
            assertNotNull("Messages not dead-lettered (" + (n-x) + " left)",
                          getResponse);
            assertEquals("test message", new String(getResponse.getBody()));
            withResponse.process(getResponse);
        }
        GetResponse getResponse = channel.basicGet(queue, true);
        assertNull("expected empty queue", getResponse);
    }
View Full Code Here

     *        to be retrievable from the respective queue
     */
    protected void checkGet(boolean[] expected) throws IOException {
        for (int i = 0; i < resources.length; i++) {
            String q = resources[i];
            GetResponse r = channel.basicGet(q, true);
            assertEquals("check " + q , expected[i], r != null);
        }
    }
View Full Code Here

    }

    private GetResponse basicGet(boolean noAck)
        throws IOException
    {
        GetResponse r = channel.basicGet(Q, noAck);
        latestTag = (r == null) ? 0L : r.getEnvelope().getDeliveryTag();
        return r;
    }
View Full Code Here

TOP

Related Classes of com.rabbitmq.client.GetResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.