When a sender delivers messages, Queues and Topics are comparable, but the recipient processes messages in a different way. A topic can have more subscribers than a queue, which can only have one consumer.
Service Bus Queue for Azure
Each message has a direct connection to its consumer while it is in a queue. A queue only permits one consumer to process a message at a time.
First In, First Out (FIFO) message delivery is provided via queues to one or more competing customers. This means that the initial message put into the queue will be the first one to be retrieved by the receiver since receivers normally receive and process messages in the order in which they were added to the queue. Additionally, each message is received and processed by a single message consumer.
Service Bus Topic for Azure
A topic (and subscriptions) offer a one-to-many relationship between each message and consumers in contrast to the queue. The publish and subscribe (pub/sub) model is used, which is helpful for scaling many receivers. Each published message is made available to each subscription registered with the topic.
Publishers can send messages to topics in the same manner they can send messages to queues, with the exception that topics may have many, independent subscriptions, which is a minor difference. Each message posted to a Topic can be copied and forwarded to a subscriber of that Topic.
Consumers don’t hear communications from the subject directly. Instead, subscribers of the subject send messages to consumers.
Subscriptions
Similar to a virtual queue, a topic subscription also gets copies of the messages that are submitted to the subject. Similar to how they receive messages from a queue, consumers receive messages through subscriptions.
A queue’s message-sending and message-receiving capabilities are directly mapped to topics and subscriptions, respectively.
Key Differences
Consumer options
Query: Multiple receivers are conceivable, but only one of them will be able to receive each message
Topic: Each message copy can be distributed to as many subscribers connected to the Topic as there are message receivers (subscribers) available.
Message Filtering
Queue: Since just one user is receiving messages in a queue, no filters are actually needed.
Topic: Every message transmitted across a Topic is capable of having a variety of attributes. When a custom filter per subscription is used, properties are utilized.
Consumer Scalability
Queue: You can only have one customer listening if you need to scale a queue.
Topic: Given that several consumers can listen to messages, topics may be more scalable than queues. The Topic doesn’t need to be started over. All new messages posted to that Topic after a new subscription has been formed will be received by the new subscriber as well.
Message Auto-forwarding
Queue: Messages may be automatically routed to a certain Topic or Queue. But a Topic Subscription cannot be the final goal.
Topic: The auto-forwarding of messages from a Topic to a Queue or Topic is an option. Additionally, messages from a Topic Subscription can be sent to a queue or topic.
Message Removal
Queue: The message cannot be handled by other readers once the initial recipient has finished reading it and removed it from the queue.
Topic: Only after each recipient has read and digested the message is it withdrawn. The message is also withdrawn from the Topic once it has been read by all of the Subscribers.