Azure服务总线-如何向消息添加元数据 [英] Azure service bus - how to add metadata to the message

查看:83
本文介绍了Azure服务总线-如何向消息添加元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将.net核心Web应用程序用作发布者,并将.net核心控制台应用程序用作订阅者. 我能够使用托管门户在Azure门户中成功设置这两个系统之间的消息传递.

I am using .net core web app as the publisher and .net core console app as subscriber. I am able to successfully pass messages between these two systems using Managed Identities - set up in Azure portal.

我的问题是我需要将元数据添加到正在发送的消息中.我该怎么办?

My question is I need to add metadata to the the message that is being sent. How do I do that ?

下面是我的发布者代码:

Below is my publisher code :

string data = JsonConvert.SerializeObject(payloadEvents);
Message message = new Message(Encoding.UTF8.GetBytes(data));

var tokenProvider = TokenProvider.CreateManagedIdentityTokenProvider();

TopicClient sendClient = new TopicClient(_serviceBusNamespace, _topicName, tokenProvider, retryPolicy: null);

await sendClient.SendAsync(message);

推荐答案

Message 对象具有名为

Message object has a property called UserProperties that can be used to set custom metadata for that message.

类似的东西:

string data = JsonConvert.SerializeObject(payloadEvents);
Message message = new Message(Encoding.UTF8.GetBytes(data));
message.UserProperties.Add("key1", "value1");
message.UserProperties.Add("key2", "value2");

var tokenProvider = TokenProvider.CreateManagedIdentityTokenProvider();

TopicClient sendClient = new TopicClient(_serviceBusNamespace, _topicName, tokenProvider, retryPolicy: null);

await sendClient.SendAsync(message);

这篇关于Azure服务总线-如何向消息添加元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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