[rabbitmq-discuss] Callback - handleDelivery

cw storm cwstorm at gmail.com
Fri Feb 7 17:28:25 GMT 2014


MK,

Thank you so much for your response.  I'm the amqp java api and create my
service.  In my service, my main try/catch blockI establish the
ConnectionFactory and Channel.  Then I assigned an executor service:
 channel.queueDeclare(QueueName, true, false, false, null);
channel.basicConsume(strQueueName, false,
new DefaultConsumer(channel) {
@Override public void handleDelivery(String consumerTag,
Envelope envelope,
AMQP.BasicProperties props,
byte[] body)
throws IOException
{}

If I understand it correctly, is the "handleDelivery" is like a listener on
the queue.  Whenever a message arrives in the queue, everything inside the
"handleDelivery" gets executed.  So, I have an object which invokes another
service residing on the client application.  Based on your explaination, I
have to ensure that the object is threaded because that's how the message
is being dispatched to the client application.  The the object that I'm
using isn't thread supported, then that'll explain the
NPE(NullPointerException) within the "handleDelivery", right?


On Fri, Feb 7, 2014 at 12:05 PM, Michael Klishin <
michael.s.klishin at gmail.com> wrote:

> 2014-02-07 17:55 GMT+04:00 cw storm <cwstorm at gmail.com>:
>
> Not sure I understand.  "Make sure your code is prepared for that."  What
>> do you mean by that.
>
>
> You instantiate Connection and Channel in one thread (often the main
> thread) but incoming messages
> are dispatched from a different thread ("main loop" or "network I/O
> thread") into a pool every connection
> has.
>
> You need to make sure that the objects used in handleDelivery are
> initialized in a thread safe
> manner (e.g. not lazily). A null pointer exception coming from
> handleDelivery suggests the problem
> is with one of the objects you use there.
>
>
>> Also, if thread pool, will it close once the broker receive a "basicAck"?
>
>
> If you did not provide a custom executor service to
> ConnectionFactory#newConnection, it will be
> shut down when connection is closed. Otherwise it's up to you to shut it
> down on application
> shutdown.
> --
> MK
>
> http://github.com/michaelklishin
> http://twitter.com/michaelklishin
>
> _______________________________________________
> 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/20140207/45a6764a/attachment.html>


More information about the rabbitmq-discuss mailing list