Azure Servicebus消息ID始终为空 [英] Azure Servicebus messageid is always null

查看:69
本文介绍了Azure Servicebus消息ID始终为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当简单的函数,可以将消息发送到Azure ServiceBus队列。

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?

推荐答案

MessageID是可以使用消息类中的公共setMessageID函数设置的属性。

在最新版本的Java客户端中,当您收到消息时会返回消息id,即使您没有设置它。如果您在发送邮件之前设置它,则在接收该邮件时,您将获得与邮件ID相同的值。

这篇关于Azure Servicebus消息ID始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆