发送到 Azure 服务总线主题的消息如何知道要转到哪个订阅?

发布于 2025-01-11 03:40:44 字数 1156 浏览 0 评论 0 原文

我想实现 Azure 服务总线主题/订阅。像这样的

“在此处输入图像描述”"

我正在查看 Azure 文档。我不明白的是,当消息发送时,它如何知道要转到哪个订阅?

def send_single_message(sender):
    # create a Service Bus message
    message = ServiceBusMessage("Single Message")
    # send the message to the topic
    sender.send_messages(message)
    print("Sent a single message")

# create a Service Bus client using the connection string
servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR, logging_enable=True)
with servicebus_client:
    # get a Topic Sender object to send messages to the topic
    sender = servicebus_client.get_topic_sender(topic_name=TOPIC_NAME)
    with sender:
        # send one message        
        send_single_message(sender)

print("Done sending messages")
print("-----------------------")

I want to implement Azure Service Bus Topic/Subscription. Something like this

enter image description here

I'm looking at the Python implementation in the Azure Docs. What I don't understand, is when the message is sent, how does it know which subscription to go to?

def send_single_message(sender):
    # create a Service Bus message
    message = ServiceBusMessage("Single Message")
    # send the message to the topic
    sender.send_messages(message)
    print("Sent a single message")

# create a Service Bus client using the connection string
servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR, logging_enable=True)
with servicebus_client:
    # get a Topic Sender object to send messages to the topic
    sender = servicebus_client.get_topic_sender(topic_name=TOPIC_NAME)
    with sender:
        # send one message        
        send_single_message(sender)

print("Done sending messages")
print("-----------------------")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手心的温暖 2025-01-18 03:40:44

我不明白的是,消息何时发送,它怎么知道
去哪个订阅?

这是通过主题过滤器完成的。发送到主题的每条消息都是“广播”(由于缺乏更好的术语)到每个订阅,并且订阅仅在该消息与为该订阅指定的过滤规则之一匹配时才接受该消息。

您可以在此处了解更多信息:https:// learn.microsoft.com/en-us/azure/service-bus-messaging/topic-filters

What I don't understand, is when the message is sent, how does it know
which subscription to go to?

This is accomplished through topic filters. Each message that gets sent to a Topic is "kind of broadcasted" (for the lack of better term) to every Subscription and the Subscription only accepts a message when that message matches one of the filter rules specified for that Subscription.

You can learn more about it here: https://learn.microsoft.com/en-us/azure/service-bus-messaging/topic-filters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文