Search code examples
javarabbitmqspring-rabbit

How long can channel keep alive while awaiting a channel.basicAck from the client


I'm curious if there were no unexpected error, will the channel stay alive while waiting for the client to acknowledge a message (using channel.basicAck())? Does a channel have a timeout parameter?

For example, will this code be problematic if xxx is very large?:

@RabbitListener(queues = DURABLE_QUEUE)
  public void listenAddAndDelete(@Payload Message message, Channel channel,@Header(AmqpHeaders.DELIVERY_TAG) long tag) {
    log.info("receive user msg: {}", message);
    // sleep very long time,then ack,is channel has a timeout?
    Thread.sleep(xxx);
    try {
      channel.basicAck(tag,false);
    } catch (IOException e) {
      //
    }
  }

In addition,When will the channel be closed under normal circumstances?


Solution

  • It generally won't timeout as long as heartbeats are enabled (which is the default), but keeping a message in that state for a long time is an anti-pattern, as I suggested in a comment to the answer referred to in the comment above.