<div dir="ltr">MK,<div><br></div><div>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:</div>
<div> channel.queueDeclare(QueueName, true, false, false, null);</div><div><span class="" style="white-space:pre"> </span>channel.basicConsume(strQueueName, false,</div><div><span class="" style="white-space:pre"> </span>new DefaultConsumer(channel) {</div>
<div><span class="" style="white-space:pre"> </span>@Override public void handleDelivery(String consumerTag,</div><div><span class="" style="white-space:pre"> </span>Envelope envelope,</div><div><span class="" style="white-space:pre"> </span>AMQP.BasicProperties props,</div>
<div><span class="" style="white-space:pre"> </span>byte[] body)</div><div><span class="" style="white-space:pre"> </span>throws IOException</div><div><span class="" style="white-space:pre"> </span>{}</div><div>
<br></div><div>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?</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 7, 2014 at 12:05 PM, Michael Klishin <span dir="ltr"><<a href="mailto:michael.s.klishin@gmail.com" target="_blank">michael.s.klishin@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
2014-02-07 17:55 GMT+04:00 cw storm <span dir="ltr"><<a href="mailto:cwstorm@gmail.com" target="_blank">cwstorm@gmail.com</a>></span>:<div class="im"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Not sure I understand. "Make sure your code is prepared for that." What do you mean by that. </blockquote><div><br></div></div><div>You instantiate Connection and Channel in one thread (often the main thread) but incoming messages</div>
<div>are dispatched from a different thread ("main loop" or "network I/O thread") into a pool every connection</div><div>has.</div><div><br></div><div>You need to make sure that the objects used in handleDelivery are initialized in a thread safe</div>
<div>manner (e.g. not lazily). A null pointer exception coming from handleDelivery suggests the problem</div><div>is with one of the objects you use there.</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Also, if thread pool, will it close once the broker receive a "basicAck"?</blockquote></div></div><br><div>If you did not provide a custom executor service to ConnectionFactory#newConnection, it will be</div><div>
shut down when connection is closed. Otherwise it's up to you to shut it down on application</div>
<div>shutdown.</div><span class=""><font color="#888888">-- <br>MK<br><br><a href="http://github.com/michaelklishin" target="_blank">http://github.com/michaelklishin</a><br><a href="http://twitter.com/michaelklishin" target="_blank">http://twitter.com/michaelklishin</a><br>
</font></span></div></div>
<br>_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
<br></blockquote></div><br></div></div>