channel.basicCancel hangs
Kristian Lind <
klindp@...>
2013-05-21 23:02:59 GMT
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.0.4</version>
</dependency>
RabbitMQ 3.0.2, Erlang R16A
I have a webpage that has a start button and a stop button.
These to buttons should start and stop the consuming messages.
When the user presses start button the consuming starts... when the user presses the stop button the consuming stops
BUT.. the user cannot start the consuming again.
While debugging the code, I see the method call channel.basicCancel hangs... and the debugger stops...
When I stop the JBoss server where the application is deployd I see this exception coming in the catch when doing channel.basicCancel.
com.rabbitmq.client.ShutdownSignalException: clean channel shutdown; reason: #method<channel.close>(reply-code=200, reply-text=OK, class-id=0, method-id=0)
And in the method handleDelivery I see ShutdownSignalException...
com.rabbitmq.client.AlreadyClosedException: clean connection shutdown; reason: Attempt to use closed channel
The call to basicCancel only hangs when consuming is going on.. if I start the consuming, but no messages are on the queue, I can stop it.. and start it again.
<at> Override
protected final synchronized void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
String task = req.getParameter("task");
...
if (StringUtils.isNotBlank(task) && task.equals("stop")) {
consuming = false;
try {
channel.basicCancel("MonitorConsumer");
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
if (connection == null || channel == null) {
createRabbitConnection();
}
if (!consuming) {
channel.basicConsume(Configuration.QUEUE_JSI_TO_DASHBOARD, false, "MonitorConsumer", this);
consuming = true;
}
}
}
public synchronized void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException {
...
try {
channel.basicAck(deliveryTag, false);
} catch (ShutdownSignalException e) {
e.printStackTrace();
}
}
<div>
<div><dependency></div>
<div>
<span class="Apple-tab-span"> </span><groupId>com.rabbitmq</groupId></div>
<div>
<span class="Apple-tab-span"> </span><artifactId>amqp-client</artifactId></div>
<div>
<span class="Apple-tab-span"> </span><version>3.0.4</version></div>
<div></dependency></div>
<div><br></div>
<div>
<span>RabbitMQ 3.0.2, Erlang R16A</span><br>
</div>
<div><span><br></span></div>
<div><span>I have a webpage that has a start button and a stop button. </span></div>
<div><span>These to buttons should start and stop the consuming messages.</span></div>
<div><span><br></span></div>
<div><span>When the user presses start button the consuming starts... when the user presses the stop button the consuming stops</span></div>
<div><span>BUT.. the user cannot start the consuming again. </span></div>
<div>
<span>While debugging the code, I see the method call </span><span>channel.basicCancel hangs... and the debugger stops... </span>
</div>
<div><span>When I stop the JBoss server where the application is deployd I see this exception coming in the catch when doing channel.basicCancel.</span></div>
<div>
<span>com.rabbitmq.client.ShutdownSignalException: clean channel shutdown; reason: #method<channel.close>(reply-code=200, reply-text=OK, class-id=0, method-id=0)</span><br>
</div>
<div><span><span><br></span></span></div>
<div>
<span><span>And in the method </span></span><span>handleDelivery I see ShutdownSignalException...</span>
</div>
<div>
<span>com.rabbitmq.client.AlreadyClosedException: clean connection shutdown; reason: Attempt to use closed channe</span><span>l</span>
</div>
<div><span><br></span></div>
<div>
<span>The call to </span>basicCancel only hangs when consuming is going on.. if I start the consuming, but no messages are on the queue, I can stop it.. and start it again. </div>
<div><br></div>
<div>
<div> <at> Override</div>
<div>protected final synchronized void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {</div>
<div>
<span class="Apple-tab-span"> </span>String task = req.getParameter("task");</div>
<div> ...</div>
<div>
<span class="Apple-tab-span"> </span>if (StringUtils.isNotBlank(task) && task.equals("stop")) {</div>
<div>
<span class="Apple-tab-span"> </span>consuming = false;</div>
<div>
<span class="Apple-tab-span"> </span>try {</div>
<div>
<span class="Apple-tab-span"> </span>channel.basicCancel("MonitorConsumer");</div>
<div>
<span class="Apple-tab-span"> </span>} catch (Exception e) {</div>
<div>
<span class="Apple-tab-span"> </span>e.printStackTrace();</div>
<div>
<span class="Apple-tab-span"> </span>}</div>
<div>
<span class="Apple-tab-span"> </span>}</div>
<div>
<span class="Apple-tab-span"> </span>} else {</div>
<div>
<span class="Apple-tab-span"> </span>if (connection == null || channel == null) {</div>
<div>
<span class="Apple-tab-span"> </span>createRabbitConnection();</div>
<div>
<span class="Apple-tab-span"> </span>}</div>
<div>
<span class="Apple-tab-span"> </span>if (!consuming) {</div>
<div>
<span class="Apple-tab-span"> </span>channel.basicConsume(Configuration.QUEUE_JSI_TO_DASHBOARD, false, "MonitorConsumer", this);</div>
<div>
<span class="Apple-tab-span"> </span>consuming = true;</div>
<div>
<span class="Apple-tab-span"> </span>}</div>
<div>
<span class="Apple-tab-span"> </span>}</div>
<div>}</div>
<div><br></div>
<div>
<div>public synchronized void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException {</div>
<div>
<span class="Apple-tab-span"> </span>...</div>
<div> try {</div>
<div>
<span class="Apple-tab-span"> </span>channel.basicAck(deliveryTag, false);</div>
<div>
<span class="Apple-tab-span"> </span>} catch (ShutdownSignalException e) {</div>
<div>
<span class="Apple-tab-span"> </span>e.printStackTrace();<br>
</div>
<div>
<span class="Apple-tab-span"> </span>}</div>
<div>}<br>
</div>
</div>
</div>
<div><br></div>
<div><br></div>
<div><br></div>
<div><span><br></span></div>
<div><span><br></span></div>
<div><span><br></span></div>
</div>