[rabbitmq-discuss] How to tell Java Client running in a separate thread to stop consuming

dusura dusura at gmail.com
Fri Oct 21 01:28:17 BST 2011


Of course, if RabbitMQ didn't swallow InterruptedException that would
solve my problem.

On Oct 21, 11:17 am, dusura <dus... at gmail.com> wrote:
> Hi Steve,
>
> thanks for your reply. Yes, I am trying to cancel a consumer from
> another thread.
>
> I am using Spring AMQP. I guess this is an issue for the Spring guys
> so I will raise it there. There doesn't seem to be any way to do this
> with the current Spring APIs.
>
> From the Spring API I am using
> AmqpTemplate.receiveAndConvert(queueName) and there no way to cancel
> this.
>
> The closest I could get was some dodgy digging into the Spring
> AmqpAdmin implementation to grab the channel and make a bad call which
> stopped my consumption by throwing
> org.springframework.amqp.AmqpIOException.
>
> e.g.
>
>         ((RabbitAdmin)amqpAdmin).getRabbitTemplate().execute(new
> ChannelCallback<Object>() {
>             @Override
>             public Object doInRabbit(Channel channel) throws Exception
> {
>
> channel.basicCancel("spring_probably_knows_this_but_i_dont");
>                 return null;
>             }
>         });
>
> Thanks,
> Dave
>
> On Oct 21, 1:09 am, Steve Powell <st... at rabbitmq.com> wrote:
>
>
>
>
>
>
>
> > I cannot tell from where you wish to stop the client.
> > I will assume you mean from another Java thread.
>
> > To start consuming, you issued basicConsume(...) and either
> > supplied a tag (java.lang.String) to or had one returned
> > from this call.  The tag identifies the consumer.  To stop
> > consuming you issue basicCancel(tag) on the same channel.  
> > This stops just this one Consumer. It can be issued from
> > another thread.
>
> > The Consumer will be called once before it stops:
> > handleCancelOk() is the last callback it receives.
>
> > But you asked about stopping a >client< from consuming; in
> > general there is no general and reliable Java way of stopping
> > a thread, and a client may in any case have several threads
> > running. To stop a whole client from consuming would require
> > application specific code.
>
> > Of course closing the channel will stop all the consumers
> > but I guess you want something less draconian.
>
> > I hope this helps you. If not, please supply more details
> > of your application and requirement.
>
> > Steve Powell  (a happy bunny)
> > ----------some definitions from the SPD----------
> > Rigatoni n. A prime-ministerial grin.
> > Nigella n. The next bottle-size up from a Nebuchadnezzar.
> > Homily adv. Rather like a frenchman.
>
> > On 20 Oct 2011, at 07:52, dusura wrote:
>
> > > Hi,
>
> > > I would like to tell a Java Client to stop consuming. The client is
> > > running in a separate thread. How can I do this?
>
> > > I tried interrupting the thread but the RabbitMQ impl swallows
> > > InterruptedException.
>
> > > Any suggestions would be appreciated.
>
> > > Cheers.
>
> > > My thread looks like this:
>
> > > "Thread-1" prio=6 tid=0x03766400 nid=0x738 in Object.wait()
> > > [0x03f0f000]
> > >   java.lang.Thread.State: WAITING (on object monitor)
> > >    at java.lang.Object.wait(Native Method)
> > >    at java.lang.Object.wait(Object.java:485)
> > >    at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:50)
> > >    - locked <0x22ce4fd8> (a
> > > com.rabbitmq.utility.BlockingValueOrException)
> > >    at
> > > com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:
> > > 89)
> > >    - locked <0x22ce4fd8> (a
> > > com.rabbitmq.utility.BlockingValueOrException)
> > >    at
> > > com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(Block ingValueOrException.java:
> > > 33)
> > >    at com.rabbitmq.client.impl.AMQChannel
> > > $BlockingRpcContinuation.getReply(AMQChannel.java:337)
> > >    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:
> > > 210)
> > >    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:
> > > 128)
> > >    at com.rabbitmq.client.impl.ChannelN.basicGet(ChannelN.java:808)
> > >    at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
> > >    at
> > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp l.java:
> > > 25)
> > >    at java.lang.reflect.Method.invoke(Method.java:597)
> > > ..............
>
> > > _______________________________________________
> > > rabbitmq-discuss mailing list
> > > rabbitmq-disc... at lists.rabbitmq.com
> > >https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
> > _______________________________________________
> > rabbitmq-discuss mailing list
> > rabbitmq-disc... at lists.rabbitmq.comhttps://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-disc... at lists.rabbitmq.comhttps://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


More information about the rabbitmq-discuss mailing list