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

Adam Rabung adamrabung at gmail.com
Thu Oct 20 18:58:07 BST 2011


Hi,
Along these same lines, is it considered thread-safe to call
channel.basicAck from a separate thread while the "host thread" for the
channel is blocked on QueueingConsumer#nextDeliver?  Better yet, when is it
not thread-safe to call basicAck from a separate thread?

Thanks,
Adam

On Thu, Oct 20, 2011 at 10:09 AM, Steve Powell <steve 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(BlockingValueOrException.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(DelegatingMethodAccessorImpl.java:
> 25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> ..............
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
>
>
> _______________________________________________
> 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/20111020/136424cb/attachment.htm>


More information about the rabbitmq-discuss mailing list