To get a glimpse into what is happening in your rabbit server there are a couple of ways to see. You can use the rabbitmq_management plugin or use rabbitmqctl list_queues.
To enable the management plugin:
Then start the rabbit server.
Then visit localhost:15672 and use the username: guest and password: guest to log in.
The management dashboard gives you a lot of information on the different queues, exchanges and a lot of other information.
To list out the queues from the command line you can run:
In the above example, I have one queue named “hello” with 0 messages.
When sending message through rabbit you can send messages directly to a single queue. This type of setup is usually good for when you have a series of worker processes that are pulling messages off of a single queue to process.
In the case when you want to publish a single message and have it broadcasted to multiple subscribers, you want to use an exchange.
When a message is published to an exchange, the exchange delivers the message to multiple queues. Different types of exchanges deliver messages to queues in different ways.
There are a few built in exchanges that you can use out of the box. They are:
To list out all the exchanges on the server:
A fanout exchange delivers a message to all the queues that it knows about. More info here.
A direct exchange delivers messages to the queue who’s routing key exactly matches the routing key of the message.
A topic exchange operates like a direct exchange. It routes messages to queues that are bound to a specify routing key. The difference is the use pattern matching in the routing key.
Routing keys can accept patterns like “*” to substitute exactly one word. Or “#” to substitute zero or more words.
Routing keys are a series of words delimited by a “.”
Bindings are used to bind a queue to an exchange. This tells the exchange to add messages to a specific queue when they are received by the exchange.
“This queue is interested in messages from this exchange.”
To list all bindings:
A binding can bind to a specific key.
In this example there is a single sender and a single receiver. In it’s simplist form you can publish a message to a specific named queue using the default exchange. By default queues are created as in memory queues and will not persist between rabbitmq restarts.
When run from the shell:
The receiver subscribes to all messages from a named queue. At this point there is a single message waiting to be delivered in rabbitmq in the “hello” queue.
From the shell:
More fun examples can be found here.