rabbitmqctl

Create admin user with full host permissions

# create new user named 'theadmin'
rabbitmqctl add_user theadmin thepassword

# make 'theadmin' admin
rabbitmqctl set_user_tags theadmin administrator

# give 'theadmin' permissions for all hosts
rabbitmqctl set_permissions -p / theadmin ".*" ".*" ".*"

AMQP Exchange Types

1. Fanout Exchange

Description: A fanout exchange routes messages to all of the queues that are bound to it. It doesn’t take the routing key into consideration. Instead, it simply broadcasts the message to all bound queues.

Use Case: Broadcasting messages to multiple consumers, such as sending notifications to all users or logging messages to multiple systems.

Example: A weather alert system that needs to send a warning to all users regardless of their location.

2. Direct Exchange

Description: A direct exchange routes messages to queues based on the message’s routing key. The message is sent to the queue whose binding key matches the routing key exactly.

Use Case: Point-to-point communication where messages need to be delivered to a specific queue. This is useful for task distribution where each task needs to be processed by one consumer.

Example: A task queue where each task is assigned to a specific worker based on a routing key.

3. Headers Exchange

Description: A headers exchange routes messages based on the headers of the message rather than the routing key. It uses the headers to determine how to route the message.

Use Case: Complex routing scenarios where routing decisions are based on multiple attributes of the message rather than just a single key.

Example: An email system where messages are routed based on multiple criteria such as sender, receiver, subject, etc.

4. Topic Exchange

Description: A topic exchange routes messages to one or many queues based on a pattern matching between the routing key and the binding key. The routing key is usually a series of words separated by dots (e.g., "log.info", "user.signup"). The binding key can contain wildcards: * * (star) matches exactly one word. * # (hash) matches zero or more words.

Use Case: Routing messages to multiple queues based on pattern matching, which is useful for implementing publish/subscribe scenarios where subscribers are interested in specific topics.

Example: A logging system where messages are categorized by severity (info, warning, error) and can be routed to different logging services based on the severity.

Summary

  • Fanout Exchange: Broadcasts messages to all bound queues, ignoring the routing key.

  • Direct Exchange: Routes messages to queues where the routing key matches the binding key exactly.

  • Headers Exchange: Routes messages based on header attributes.

  • Topic Exchange: Routes messages based on pattern matching of routing keys and binding keys, supporting wildcards for flexible routing.