Package com.rabbitmq.client

Examples of com.rabbitmq.client.Consumer


    Channel delegate;
    ChannelHandler channelHandler;
    Map<Integer, Consumer> consumers = new HashMap<Integer, Consumer>();

    protected Consumer mockConsumer(String queueName, int consumerNumber) throws IOException {
      Consumer consumer = consumers.get(consumerNumber);
      if (consumer == null) {
        String consumerTag = String.format("%s-%s", delegate.getChannelNumber(), consumerNumber);
        consumer = new MockConsumer(proxy, consumerNumber);
        when(delegate.basicConsume(eq(queueName), argThat(matcherFor(consumer)))).thenReturn(
            consumerTag);
View Full Code Here


    doAnswer(failNTimes(1, nonRetryableChannelShutdownSignal(), null, mockChannel.channelHandler)).when(
        mockChannel.delegate)
        .basicCancel("foo-tag");

    final LinkedBlockingQueue<Long> tags = new LinkedBlockingQueue<Long>();
    final Consumer consumer = new DefaultConsumer(mockChannel.proxy) {
      @Override
      public void handleDelivery(String consumerTag, Envelope envelope,
          AMQP.BasicProperties properties, byte[] body) throws IOException {
        try {
          System.out.println("Received " + envelope.getDeliveryTag());
View Full Code Here

      returnListeners.clear();
  }

  private String handleConsumerDeclare(Method method, Object[] args) throws Exception {
    if (config.isConsumerRecoveryEnabled()) {
      Consumer consumer = (Consumer) args[args.length - 1];
      args[args.length - 1] = new ConsumerDelegate(this, consumer);
      String consumerTag = (String) Reflection.invoke(delegate, method, args);
      if (args.length > 3)
        args[2] = consumerTag;
      String queueName = "".equals(args[0]) ? lastGeneratedQueueName : (String) args[0];
View Full Code Here

            throws InterruptedException, IOException {
        Map<String, Object> args = new HashMap<String, Object>();
        args.put("x-expires", QUEUE_EXPIRES);
        channel.queueDeclare(TEST_EXPIRE_QUEUE, false, false, false, args);

        Consumer consumer = new DefaultConsumer(channel);
        String consumerTag = channel.basicConsume(TEST_EXPIRE_QUEUE, consumer);

        Thread.sleep(SHOULD_EXPIRE_WITHIN);
        try {
            channel.queueDeclarePassive(TEST_EXPIRE_QUEUE);
View Full Code Here

    public void testConsumerCancellationNotification() throws IOException,
            InterruptedException {
        final BlockingQueue<Boolean> result = new ArrayBlockingQueue<Boolean>(1);

        channel.queueDeclare(queue, false, true, false, null);
        Consumer consumer = new QueueingConsumer(channel) {
            @Override
            public void handleCancel(String consumerTag) throws IOException {
                try {
                    result.put(true);
                } catch (InterruptedException e) {
View Full Code Here

                        new byte[0]);
    }

    public void testIt() throws IOException, InterruptedException {

        final Consumer c = new DefaultConsumer(channel);

        //1. create lots of auto-delete queues, bind them to the
        //amq.fanout exchange, and set up a non-auto-ack consumer for
        //each.
        for (int i = 0; i < Q_COUNT; i++) {
View Full Code Here

            // We're in normal running mode.

            if (method instanceof Basic.Deliver) {
                Basic.Deliver m = (Basic.Deliver) method;

                Consumer callback = _consumers.get(m.getConsumerTag());
                if (callback == null) {
                    if (defaultConsumer == null) {
                        // No handler set. We should blow up as this message
                        // needs acking, just dropping it is not enough. See bug
                        // 22587 for discussion.
                        throw new IllegalStateException("Unsolicited delivery -" +
                                " see Channel.setDefaultConsumer to handle this" +
                                " case.");
                    }
                    else {
                        callback = defaultConsumer;
                    }
                }

                Envelope envelope = new Envelope(m.getDeliveryTag(),
                                                 m.getRedelivered(),
                                                 m.getExchange(),
                                                 m.getRoutingKey());
                try {
                    this.dispatcher.handleDelivery(callback,
                                                   m.getConsumerTag(),
                                                   envelope,
                                                   (BasicProperties) command.getContentHeader(),
                                                   command.getContentBody());
                } catch (Throwable ex) {
                    getConnection().getExceptionHandler().handleConsumerException(this,
                                                                                  ex,
                                                                                  callback,
                                                                                  m.getConsumerTag(),
                                                                                  "handleDelivery");
                }
                return true;
            } else if (method instanceof Basic.Return) {
                callReturnListeners(command, (Basic.Return) method);
                return true;
            } else if (method instanceof Channel.Flow) {
                Channel.Flow channelFlow = (Channel.Flow) method;
                synchronized (_channelMutex) {
                    _blockContent = !channelFlow.getActive();
                    transmit(new Channel.FlowOk(!_blockContent));
                    _channelMutex.notifyAll();
                }
                callFlowListeners(command, channelFlow);
                return true;
            } else if (method instanceof Basic.Ack) {
                Basic.Ack ack = (Basic.Ack) method;
                callConfirmListeners(command, ack);
                handleAckNack(ack.getDeliveryTag(), ack.getMultiple(), false);
                return true;
            } else if (method instanceof Basic.Nack) {
                Basic.Nack nack = (Basic.Nack) method;
                callConfirmListeners(command, nack);
                handleAckNack(nack.getDeliveryTag(), nack.getMultiple(), true);
                return true;
            } else if (method instanceof Basic.RecoverOk) {
                for (Map.Entry<String, Consumer> entry : _consumers.entrySet()) {
                    this.dispatcher.handleRecoverOk(entry.getValue(), entry.getKey());
                }
                // Unlike all the other cases we still want this RecoverOk to
                // be handled by whichever RPC continuation invoked Recover,
                // so return false
                return false;
            } else if (method instanceof Basic.Cancel) {
                Basic.Cancel m = (Basic.Cancel)method;
                String consumerTag = m.getConsumerTag();
                Consumer callback = _consumers.remove(consumerTag);
                if (callback == null) {
                    callback = defaultConsumer;
                }
                if (callback != null) {
                    try {
                        callback.handleCancel(consumerTag);
                    } catch (Throwable ex) {
                        getConnection().getExceptionHandler().handleConsumerException(this,
                                                                                      ex,
                                                                                      callback,
                                                                                      consumerTag,
View Full Code Here

    /** Public API - {@inheritDoc} */
    public void basicCancel(final String consumerTag)
        throws IOException
    {
        final Consumer originalConsumer = _consumers.get(consumerTag);
        if (originalConsumer == null)
            throw new IOException("Unknown consumerTag");
        BlockingRpcContinuation<Consumer> k = new BlockingRpcContinuation<Consumer>() {
            public Consumer transformReply(AMQCommand replyCommand) {
                replyCommand.getMethod();
View Full Code Here

    public void testConsumerCancellationNotification() throws IOException,
            InterruptedException {
        final BlockingQueue<Boolean> result = new ArrayBlockingQueue<Boolean>(1);

        channel.queueDeclare(queue, false, true, false, null);
        Consumer consumer = new QueueingConsumer(channel) {
            @Override
            public void handleCancel(String consumerTag) throws IOException {
                try {
                    result.put(true);
                } catch (InterruptedException e) {
View Full Code Here

                        new byte[0]);
    }

    public void testIt() throws IOException, InterruptedException {

        final Consumer c = new DefaultConsumer(channel);

        //1. create lots of auto-delete queues, bind them to the
        //amq.fanout exchange, and set up a non-auto-ack consumer for
        //each.
        for (int i = 0; i < Q_COUNT; i++) {
View Full Code Here

TOP

Related Classes of com.rabbitmq.client.Consumer

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.