[rabbitmq-discuss] Handling Consumer Cancel Notifications in Java Client

Chris stuff at moesel.net
Fri Aug 9 15:15:52 BST 2013


I'm an optimistic person, so I just had to try 3.1.4.  But... you are
right.  It does not work there either.

The good news is that I've updated the handleCancel method to consume from
a new thread (as you suggested) and that seems to work!  Is this
essentially what you had in mind?

        @Override
        public void handleCancel(String consumerTag) throws IOException {
            System.out.println("handleCancel: " + consumerTag);
            super.handleCancel(consumerTag);

            final SimpleConsumer self = this;
            Runnable reconsumeTask = new Runnable() {
                    @Override
                    public void run() {
                        try {
                            String cTag = getChannel().basicConsume(queue,
self);
                            System.out.println("basic(Re)Consume: " + cTag);
                        } catch (IOException e) {
                            System.err.println("basic(Re)Consume FAILED");
                            e.printStackTrace();
                        }
                    }
                };
            new Thread(reconsumeTask).start();
        }


If I recall, it's generally recommended that you not use the same channel
in multiple threads-- but I guess this is an exception to the rule?

Thanks again for the help!
Chris


On Fri, Aug 9, 2013 at 9:41 AM, Michael Klishin <mklishin at gopivotal.com>wrote:

> Michael Klishin:
>
> > This looks like a bug in the Java client.
>
> Using basicConsume from another (e.g. newly created) thread is how you can
> work
> around this issue. Passing this for consumer reference instead of
> instantiating a new
> consumer should work fine.
> --
> MK
>
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130809/fcff2389/attachment.htm>


More information about the rabbitmq-discuss mailing list