简体   繁体   English

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

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

相关问题 使用适用于 .Net 的 Azure Bob Storage v12 SDK 进行加密 - Encryption with Azure Bob Storage v12 SDK for .Net v12 .NET SDK 中的 Azure Storage BlobClient 和 BlockBlobClient 有什么区别? - What is the difference between the Azure Storage BlobClient and BlockBlobClient in v12 .NET SDK? Azure Blob 存储使用 Key Vault.Net v12 解密 SDK - Azure Blob Storage Decrypt Using Key Vault .Net v12 SDK 上传大文件 Azure Blob .net SDK v12 问题 - Upload Larget File Azure Blob .net SDK v12 Problem Azure Blob 存储 SDK v12 - BlobClient DownloadAsync 消失了吗? - Azure Blob Storage SDK v12 - BlobClient DownloadAsync gone? 如何使用 Azure.Storage v12 SDK 从 Azure Blob 中删除元数据? - How can I remove metadata from an Azure Blob using Azure.Storage v12 SDK? 使用 Azure 下载 Blob Blob 存储客户端库 v12 for .NET - Download blob using Azure Blob storage client library v12 for .NET Azure SQL V12的最佳流利NHibernate配置? - Best fluent NHibernate configuration for Azure SQL V12? 在Azure Studio V12数据库的Visual Studio 2012中未加载SSDT项目 - SSDT project not loading in visual studio 2012 for azure v12 database 如何在隔离的 Azure 函数 v4 中获取消息元数据 - c# 中的队列触发器 - How to get message metadata in isolated Azure functions v4 - Queue Trigger in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM