将消息添加到Azure消息队列时,是否可以获取消息ID(引导字符串)?
var storageAccount = CloudStorageAccount.Parse(Storage.ConnectionString);
var queueClient = storageAccount.CreateCloudQueueClient();
var messageQueue = queueClient.GetQueueReference(Storage.Queue.Property);
await messageQueue.AddMessageAsync(message: new CloudQueueMessage(message)
, timeToLive: TimeSpan.MaxValue
, initialVisibilityDelay: null
, options: null
, operationContext: null);
// How do I get message Id
我需要能够创建队列中内容的日志,并且在将项目添加到队列中时以及消息ID接缝要在内部创建的Azure中创建,而无需传递任何选项。
答案 0 :(得分:1)
好的,没问题。发送后,只需阅读消息的ID属性即可:
var storageAccount = CloudStorageAccount.Parse(Storage.ConnectionString);
var queueClient = storageAccount.CreateCloudQueueClient();
var messageQueue = queueClient.GetQueueReference(Storage.Queue.Property);
var queueMessage = new CloudQueueMessage(message);
await messageQueue.AddMessageAsync(message: queueMessage
, timeToLive: TimeSpan.MaxValue
, initialVisibilityDelay: null
, options: null
, operationContext: null);
// How do I get message Id
Console.WriteLine(queueMessage.Id);