我有一个相当简单的函数,它向蔚蓝的服务总线队列发送消息。Azure Servicebus messageid始终为空
public async Task<string> SendMessagesToQueue(string serviceBusConnectionString, int message, string queueName)
{
try
{
QueueClient queueClient = new QueueClient(serviceBusConnectionString, queueName, ReceiveMode.PeekLock);
// Create a new brokered message to send to the queue
var brokeredMessage = new Message($"Message {message}");
// Send the message to the queue
await queueClient.SendAsync(brokeredMessage);
await queueClient.CloseAsync();
// Delay by 10 milliseconds so that the console can keep up
await Task.Delay(10);
return brokeredMessage.MessageId;
}
catch (Exception ex)
{
return ex.ToString();
throw;
}
}
这工作正常,并将消息放入队列中。但是,brokeredMessage.MessageId始终为空。
是否有更好的方法来检索消息ID?
不够公平。有没有一种方法可以让队列中的消息的ID?像Id = b192187a-52a9-45a6-ba6f-c4b32ec9eb45 – w2olves
如果我正确地理解了你,你只需要收到这个消息并从它得到这个'MessageId'。你可以很容易地做到这一点[这里](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues#4例如,从队列中接收消息)。 – matterai
你明白我的意思。但是,这不是Microsoft.Azure.Management.ServiceBus库上提供的功能。 – w2olves