繁体   English   中英

使用 Node.js Azure function 将消息的自定义属性发送到服务总线主题

[英]Using a Node js Azure function to send custom properties on a message to a service bus topic

我正在使用 Nodejs Azure function 将消息发送到服务总线主题。 我想对该消息使用自定义属性来过滤允许哪些订阅处理消息。 这就是我的 Azure function 代码的样子。

绑定

 { "bindings": [ { "type": "serviceBus", "direction": "out", "connection": "ServiceBusConnectionString", "name": "event", "topicName": "mytopic" } ] }

索引.js

 const event = { id: eventId, dataVersion: version, eventType: eventType, data: data, eventTime: eventTime, customProperties: { number: 5 } } context.bindings.event = JSON.stringify(event);

事件到达主题但未被我的订阅过滤,因为数字未显示为自定义属性。 我通过在 Azure 中创建一个测试过滤器来验证这一点,然后使用服务总线资源管理器查看消息。

有人可以帮助我以正确的方式传递自定义属性。 对某些示例的任何引用都会有所帮助,因为官方文档没有解释如何执行此操作。 作为参考,此页面有一个示例,说明如何在不使用 Azure 函数的情况下实现此目的https://github.com/Huachao/azure-content/blob/master/articles/service-bus/service-bus-nodejs-how-使用主题订阅.md

  • 事件模式:下面提到的是所有事件发布者使用的属性:
[ 
{ "topic": string, 
"subject": string, 
"id": string, 
"eventType": string, 
"eventTime": string,
 "data":{ 
     object-unique-to-each-publisher 
     },
"dataVersion": string, 
"metadataVersion": string 
}
]

  • MSDOC中所述,应用程序特定属性可用于服务总线中的自定义消息元数据。
applicationProperties?: [key: string]: function.

例子:

MessageId?: string|int|Buffer

  • 我还观察到这可以通过 Service Bus Explorer 手动尝试来实现:
  1. 发送消息

在此处输入图像描述

  1. 可以为消息配置两种类型的属性,如下所示:

在此处输入图像描述

  1. 配置自定义属性:

在此处输入图像描述

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM