renewLock method

  1. @override
Future renewLock(
  1. MessageEnvelope message,
  2. int lockTimeout

Renews a lock on a message that makes it invisible from other receivers in the queue. This method is usually used to extend the message processing time.

  • message a message to extend its lock.
  • lockTimeout a locking timeout in milliseconds. Return (optional) Future that receives or null for success. Throws error


Future renewLock(MessageEnvelope message, int lockTimeout) async {
  if (message.getReference() == null) {
    return null;

  // Get message from locked queue
  int lockedToken = message.getReference();
  var lockedMessage = _lockedMessages[lockedToken];

  // If lock is found, extend the lock
  if (lockedMessage != null) {
    var now =;
    // TODO: Shall we skip if the message already expired?
    if (lockedMessage.expirationTime!.millisecondsSinceEpoch >
        now.millisecondsSinceEpoch) {
      lockedMessage.expirationTime =
          now.add(Duration(milliseconds: lockedMessage.timeout!));

  logger.trace(message.correlation_id, 'Renewed lock for message %s at %s',
      [message, toString()]);