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?
2
Answers
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
Using below code, we can send the message successfully and i have followed Microsoft_Document:
Used rest api
https://{ri_name_space}.servicebus.windows.net/{ri_topic_name}/messages
:Output: