cody-greene / node-rabbitmq-client

RabbitMQ (0-9-1) client library with auto-reconnect & zero dependencies
MIT License
130 stars 9 forks source link

Consumer return code #21

Closed cody-greene closed 1 year ago

cody-greene commented 1 year ago

A ConsumerHandler can return a status code for precise control of ack/nack behavior. An enum type is provided for convenience, but it's not necessary.

import {ConsumerStatus} from 'rabbitmq-client'

const sub = rabbit.createConsumer({
  queue: 'my-queue',
  requeue: false // behavior with exceptions
}, async (msg) => {
  // optionally return a status code
  // 0 or undefined - ack
  // 1              - nack(requeue=true)
  // 2              - nack(requeue=false)
  return ConsumerStatus.REQUEUE // 1
})
cody-greene commented 1 year ago

fixes #20