繁体   English   中英

使用 .NET v12 SDK 获取发送到 Azure 队列的消息的 messageId

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM