Skip to main content

RabbitMQ tutorial - Topics

Topics​

(using the AMQP 1.0 .NET client)​

info

Prerequisites​

This tutorial assumes RabbitMQ is installed and running on localhost on the standard port (5672). In case you use a different host, port or credentials, connections settings would require adjusting.

Where to get help​

If you're having trouble going through this tutorial you can contact us through GitHub Discussions or RabbitMQ community Discord.

In the previous tutorial we used a direct exchange to route by a single criterion (severity). Topic exchanges route by patterns in the routing key — useful when messages carry multiple dimensions (for example kern.critical).

The sample declares exchange logs_topic with type topic. The publisher sets the routing key on PublisherBuilder().Exchange(exchangeName).Key(routingKey). The consumer passes one or more binding keys (patterns) on the command line and binds the temporary queue for each.

Topic binding rules:

  • * substitutes exactly one word.
  • # substitutes zero or more words.
  • Words are separated by . in routing keys.

Running​

dotnet run --project ReceiveLogsTopic/ReceiveLogsTopic.csproj "kern.*"
dotnet run --project EmitLogTopic/EmitLogTopic.csproj kern.critical "A critical kernel error"

Source​

Now we can move on to tutorial 6 to learn about the RPC (request/reply) pattern with RabbitMQ.