I have this code on consumer side of a Spring RabbitMQ based application -
public class MyReceiver implements ChannelAwareMessageListener {
public MyReceiver() {
super();
}
@Autowired
@Qualifier("some_name")
private SomeDependency dep;
@Override
public void onMessage(Message message, Channel channel) throws Exception {
try {
String messageString = new String(message.getBody());
if (StringUtils.isNotEmpty(messageString)) {
LOGGER.info("Received Message is:" + messageString);
dep.someMethod();
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
}
} catch (Exception e) {
}
}
}
When I put break at the first line inside try, control reaches the breakpoint and the goes on to execute the LOGGER.info() call after it but the further lines do not execute most of the time and control moves out somewhere else before it can get there. How do I ensure that entire code inside onMessage is executed?
Here is the console output -
INFO : mypackage.MyReceiver - Received Message is:{"some thing here"} DEBUG: org.springframework.amqp.rabbit.connection.CachingConnectionFactory - Closing cached Channel: AMQChannel(amqp://[email protected]:5672/,2) ERROR: org.springframework.amqp.rabbit.connection.CachingConnectionFactory - Channel shutdown: channel error; protocol method: #method(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 1, class-id=60, method-id=80) DEBUG: org.springframework.amqp.rabbit.listener.BlockingQueueConsumer - Retrieving delivery for Consumer: tags=[{amq.ctag-utTZhTES5HFCGizQGiFWqg=tx.mt.sessionstats.recvq}], channel=Cached Rabbit Channel: AMQChannel(amqp://[email protected]:5672/,3), acknowledgeMode=AUTO local queue size=0 DEBUG: org.springframework.amqp.rabbit.listener.BlockingQueueConsumer - Received shutdown signal for consumer tag=amq.ctag-utTZhTES5HFCGizQGiFWqg com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 1, class-id=60, method-id=80) at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:484) at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:321) at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144) at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91) at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:554) at java.lang.Thread.run(Thread.java:745) DEBUG: org.springframework.test.context.support.DirtiesContextTestExecutionListener - After test class: context [DefaultTestContext@4ddced80 testClass = MyReceiverUnitTest, testInstance = [null], testMethod = [null], testException = [null],