如何将服务总线消息发送到 NodeJS 中的死信队列?

How to send service bus message to deadletter queue in NodeJS?

如何将消息发送到死信队列?

serviceBusService.receiveQueueMessage(MESSAGE_QUEUE, {isPeekLock: true}, (error, message) => {
    ...... // want to put message to deadletter queue if there is exception
    serviceBusService.deleteMessage(message, error => {
    });
});

大多数情况下,您希望依靠系统来决定何时将消息移动到 DLQ 并尽可能使其成为消息引擎的责任(而不是明确地将消息放在 DLQ 上。)它也出现此场景中的指南是通过此处的文档提供的:How to handle application crashes and unreadable messages

看起来您正在使用依赖于 HTTP REST api 的旧 azure-sb 包。如果您改为使用更新的 @azure/service-bus 包,它使用更快的 AMQP 实现,在您收到的消息上有一个 deadletter() 方法,您可以使用该方法将消息发送到死信队列。