azureazureservicebus

Azure Service Bus Topic - Using REST API to Send Message - Message going into Dead Letter Queue


I am using the Azure Service Bus API to send a message into a topic. This is the API - https://learn.microsoft.com/en-us/rest/api/servicebus/send-message-to-queue

I am getting a 201 as expected, so the call is successful. But the message gets delivered into the Dead Letter Queue.Since I am calling via the API, I do not get a DeadLetterErrorDescription or anything like that back which I would normally get if I were using the SDK.

I researched and found that some folks have overcome this issue by passing a session id, which again would be possible only if I am using the SDK.

Any thoughts on how to troubleshoot this issue?


Solution

  • I was able to find out the reason why the messages got dead lettered. The dead letter error description is "Session enabled entity doesn't allow a message whose session identifier is null". So because the topic is setup as session enabled, a session id is expected to be passed.

    While using the REST API to send messages, a session id can be passed by setting a header property named "BrokerProperties". The documentation for that is here - https://learn.microsoft.com/en-us/rest/api/servicebus/message-headers-and-properties

    By setting a header property like the one below, I was able to send a message and it reached the topic/subscription successfully without getting dead lettered.

    "BrokerProperties" as key and "{“SessionId”: “{1234}”" as value