Azure Function v2中的BrokeredMessage发送和消息使用者 [英] BrokeredMessage send and Message consumer in Azure Function v2

查看:69
本文介绍了Azure Function v2中的BrokeredMessage发送和消息使用者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有模拟的天蓝色Web作业,像这样定期将BrokeredMessage推送到服务总线主题

I have mock azure web jobs, which periodically push BrokeredMessage to the service bus topic, like this

public void Simulate(
            [TimerTrigger("0 */30 * * * *", RunOnStartup = true)]
            TimerInfo timerInfo,
            [ServiceBus("%topic%")]
            out BrokeredMessage message)
        {
            message = new BrokeredMessage(
                new AwesomeContract()
                {

                });
        }

在azure函数V2中,我试图使用Message类使用它.

In azure function V2, I am trying to consume it using Message class.

public static void Integrate(
            [ServiceBusTrigger(
                "%topic%",
                "%subscribtion%",
                Connection = "ServiceBusConnection")] Message message,
            TraceWriter log,
            ExecutionContext context)
        {
            try
            {
              message.GetBody<AwesomeContract>();
            }
        }

GetBody<>上,我收到DataContractSerialization异常"将类型的对象反序列化时出错.输入源的格式不正确."

On GetBody<> I receive DataContractSerialization exception "There was an error deserializing the object of type . The input source is not correctly formatted."

天蓝色函数v1和v2中的BrokeredMessageMessage是否兼容?有什么建议吗?

Are BrokeredMessage and Message compatible in azure function v1 and v2? Any suggestions?

推荐答案

BrokeredMessage是WindowsAzure.ServiceBus库中的消息对象,其中Message是Microsoft.Azure.ServiceBus库中的对象.

BrokeredMessage is the message object from the library WindowsAzure.ServiceBus, where Message is the object from the library Microsoft.Azure.ServiceBus.

尽管这些库之间的对象类型不同,但将邮件正文作为Stream发送将有助于克服读取正文时的异常.

Even though the object type differs between these libraries, sending the message body as a Stream will help in overcoming the exception while reading the body.

message = new BrokeredMessage(new MemoryStream(Encoding.UTF8.GetBytes([message_body]));

按上述方式构造消息会有所帮助.

Constructing the message as above will help.

这篇关于Azure Function v2中的BrokeredMessage发送和消息使用者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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