java spring rabbit - gracefully reject a message

Viewed 3739

I have the following listener method:

@Override
public void onMessage(Message message, Channel channel) {
  try {
    // do something bad :)
  } catch (Exception e){
    try {
      long dt = null != message.getMessageProperties() 
          ? message.getMessageProperties().getDeliveryTag() 
          : 0;
      channel.basicReject(dt, true);
    } catch(IOException io) {
      logger.error("IO-COMMON", io);
    }
  }
}

The issue is basic reject doesn't work, I don't know why. How to reject it gracefully? I think that if I reject a message, it should be requeued and reside is sth like cache, before going to next worker. But in fact this message just seems to be lost.

1 Answers
Related