gpt4 book ai didi

javascript - 使用 Node js Azure 函数将消息上的自定义属性发送到服务总线主题

转载 作者:行者123 更新时间:2023-12-03 06:42:39 26 4
gpt4 key购买 nike

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

绑定(bind)

{
"bindings": [

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

index.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-to-use-topics-subscriptions.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. 发送消息

enter image description here

  • 可以为消息配置两种类型的属性,如下所示:
  • enter image description here

  • 配置了自定义属性:
  • enter image description here

    enter image description here

    关于javascript - 使用 Node js Azure 函数将消息上的自定义属性发送到服务总线主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74397552/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com