[英]Get messageId of message sent to Azure queue with .NET v12 SDK
How can I get the messageId
of a message I send to a queue using .NET v12?如何获取使用 .NET v12 发送到队列的消息的
messageId
?
This answer https://stackoverflow.com/a/56407472/11636360 in Get message ID in Azure queue shows how it can be done in .NET v11, but .NET v12 SendMessage
method only accepts a string input. This answer https://stackoverflow.com/a/56407472/11636360 in Get message ID in Azure queue shows how it can be done in .NET v11, but .NET v12
SendMessage
method only accepts a string input.
Here's a code snippet from Microsoft website to put a message in a queue using .NET v12.这是来自Microsoft 网站的代码片段,用于使用 .NET v12 将消息放入队列中。
Cycling through PeekMessages
afterwards and look for a message with the same content is all I can think of but doesn't seem very neat or would necessarily work with a large number of messages in the queue.之后循环浏览
PeekMessages
并查找具有相同内容的消息是我所能想到的,但看起来不是很整洁,或者必须处理队列中的大量消息。
// Get the connection string from app settings
string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];
// Instantiate a QueueClient which will be used to create and manipulate the queue
QueueClient queueClient = new QueueClient(connectionString, queueName);
// Create the queue if it doesn't already exist
queueClient.CreateIfNotExists();
if (queueClient.Exists())
{
// Send a message to the queue
queueClient.SendMessage(message);
}
SendMessage
method returns an object of type Response<SendReceipt>
. SendMessage
方法返回Response<SendReceipt>
类型的 object 。 Looking at the documentation for SendReceipt
, you should be able to get the message id from its MessageId
property.查看
SendReceipt
的文档,您应该能够从其MessageId
属性中获取消息 ID。
Please try something like:请尝试类似:
if (queueClient.Exists())
{
// Send a message to the queue
var response = queueClient.SendMessage(message);
var messageId = response.Value.MessageId;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.