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

How do messages sent to an Azure Service Bus Topic know which subscription to go to?

我想实施 Azure 服务总线 Topic/Subscription。像这样

我正在查看 Azure Docs 中的 Python 实现。我不明白的是,发送消息时,它如何知道要转到哪个订阅?

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("-----------------------")

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

这是通过 topic filters 完成的。发送到主题的每条消息都“有点广播”(因为缺少更好的术语)到每个订阅,订阅仅在该消息匹配为该订阅指定的过滤规则之一时才接受该消息。

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