RabbitMQ is a popular and easy-to-use Message Queue.
Concepts
-
Queue: A queue is a buffer that stores messages
- Temporary Queues
- Set queue name to empty string to use a random queue name
channel.assertQueue('', {exclusive: true});
- Set queue name to empty string to use a random queue name
- Temporary Queues
-
Exchange
- Exchange determine which queue a message goes to depending on the exchange type
- Types
direct
:topic
:headers
:fanout
: broadcast all messages it receives to all the queues it knows- This could be useful for
logs
exchange, where multiplelogs
consumers handles logs differently, e.g. save to different locations
- This could be useful for
-
Bindings
-
Binding describes the relationship between exchange and a queue
-
Create a queue and bind the queue to exchange
channel.bindQueue(queue_name, 'logs', '');
-
Routing
-
Bindings can take an extra binding key parameter.
fanout
exchanges ignores this binding key- In
direct
exchanges, messages go to the queues whose binding key exactly matches the routing key
-
channel.bindQueue(queue_name, exchange_name, 'black');
-
channel.publish(exchangeName, bindingKey, Buffer.from(msg));
-
-
-
Topics
- In
topic
exchange, the routing key must be a list of words, delimited by dots.*
(star) can substitute for exactly one word.#
(hash) can substitute for zero or more words.
- In