Timothy Pulliam
Timothy Pulliam

Reputation: 142

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

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

Upvotes: 0

Views: 620

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136126

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.

Upvotes: 1

Related Questions