[英]Get messageId of message sent to Azure queue with .NET v12 SDK
如何获取使用 .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.
这是来自Microsoft 网站的代码片段,用于使用 .NET v12 将消息放入队列中。
之后循环浏览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
方法返回Response<SendReceipt>
类型的 object 。 查看SendReceipt
的文档,您应该能够从其MessageId
属性中获取消息 ID。
请尝试类似:
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.