javascriptazure-functionsazure-servicebus-subscriptions

Javascript : to explicitly send a message to dead letter queue in azure function app which is service bus triggered


I have service bus triggered azure function app. In the function app based on some condition i want to transfer the message to dead letter queue.

const sbClient = new ServiceBusClient(connectionString);
    const receiver = sbClient.createReceiver('chattopic', 'test', {
        receiveMode: "receiveAndDelete"
    });
    console.log(serviceBusMessage);
   await receiver.deadLetterMessage(serviceBusMessage, {
        deadLetterReason: "Error",
        deadLetterErrorDescription: "Error."
    })

However i get the following error

Result: Failure
Exception: The operation is not supported in 'receiveAndDelete' receive mode.
Stack: Error: The operation is not supported in 'receiveAndDelete' receive mode.

I get same error even when i change the receiveMode to peekLock. Can anyone please help here.


Solution

  • module.exports = async  function(context, mySbMsg) {
    throw new Error('Exception');
    }
    

    Before sending the message: enter image description here

    After sending the message: enter image description here

    Local terminal : enter image description here