I am using the Azure Storage Queue Client to send base 64 encoded string messages. A very straight forward usage. I have the following code snippet:
var options = new QueueClientOptions
{
MessageEncoding = QueueMessageEncoding.Base64
};
var _queueClient = new QueueClient(settings.Value.ConnectionString, settings.Value.Name, options);
var message = JsonConvert.SerializeObject(messageObject, jsonSetting);
_queueClient.SendMessageAsync(message);
I know that SendMessageAsync( . . .)
returns Response<SendReceipt>
how do I use that to verify if a message is sent successfully or not ?
SendReceipt
has MessageId
and InsetionTime
properties but the documentation does not specify what happens to these properties if message does not get sent. Does the queue simply returns null receipt or an object with default values ?
When you try to send a message to a queue using SendMessageAsync
and if for some reason message is not sent, an exception is raised. You will not receive anything in the Response<SendReceipt>
.
You will need to wrap your await _queueClient.SendMessageAsync(message);
in a try/catch block. If no exception is raised that would mean the message is sent successfully.