onebeyond / rascal

A config driven wrapper for amqp.node supporting multi-host connections, automatic error recovery, redelivery flood protection, transparent encryption / decryption and channel pooling.
MIT License
451 stars 69 forks source link

No Retries #157

Closed heroic closed 3 years ago

heroic commented 3 years ago

I tried to follow the advanced example to setup rascal. However it seems, the failed messages are being directly sent to dead letter without retries.

Tried to follow the example to see if if I missed anything, but doesn't appear so.

    recovery: {
      deferred_retry: [{
        strategy: 'forward',
        attempts: 10,
        publication: 'retry_in_1m',
        xDeathFix: true // See https://github.com/rabbitmq/rabbitmq-server/issues/161
      }, {
        strategy: 'nack'
      }],

      dead_letter: [{
        strategy: 'republish',
        immediateNack: true
      }]
    },

    redeliveries: {
      counters: {
        shared: {
          size: 10,
          type: isMaster ? 'inMemory' : 'inMemoryCluster'
        }
      }
    },
        // Setup subscriptions
        subscriptions: {
          consumer: {
            queue: [`${(process.env.NAMESPACE || '').replace(/^jx-/, '').replace(/[^a-zA-Z0-9]/g, '_')}_${process.env.APP_NAME}`],
            redeliveries: {
              limit: 10,
              counter: 'shared'
            }
          },
        },
cressie176 commented 3 years ago

Hi @heroic ,

Can you share the code you are using to ackOrNack with the error please?

Also can you set the DEBUG environment variable to rascal:SubscriberError and share the output.

heroic commented 3 years ago

Hi @cressie176

Logs:

a9102727-cf5c-4641-bea6-cbde38c662c6 Error Processing 
  rascal:SubscriberError Handling subscriber error for message: a9102727-cf5c-4641-bea6-cbde38c662c6 +0ms
  rascal:SubscriberError Attempting to recover message: a9102727-cf5c-4641-bea6-cbde38c662c6 using strategy: fallback-nack +3ms
  rascal:SubscriberError Message: a9102727-cf5c-4641-bea6-cbde38c662c6 was recovered using stragegy: fallback-nack +8ms

Code:

  broker.subscribe('consumer').then(subscription => subscription.on('message', async (message, content, ackOrNack) => {
      console.log(message.properties.messageId, 'Got data', content);
      return handler(content.name, content.args).then(result => {
        if (result === true) {
          console.log(message.properties.messageId, 'Finished Processing', result);
          return ackOrNack()
        } else {
          throw new Error(result)
        }
      }).catch((e) => {
        console.log(message.properties.messageId, 'Error Processing', e.message);
        return ackOrNack(e)
      });
    }).on('error', console.error))
cressie176 commented 3 years ago

Hi @heroic, you need to specify the recovery strategy when rejecting a message. Because you aren't doing this, rascal is using the default "fallback" recovery strategy, which is a nack. See here.

heroic commented 3 years ago

aah ok! I assumed it will follow the recovery strategies as in the configuration in the order they were added. got it!

cressie176 commented 3 years ago

I agree it's odd that they are not really part of the rascal configuration. I could consider overloading ackOrNack so it accepted a recovery strategy profile name, which it attempted to find in config.

ackOrNack(err, 'dead_letter');