...
sys.q.audit.01
- a queue bound tosys.ex.audit
sys.q.dead.letter.01
- a queue bound tosys.ex.auditdead.letter
sys.q.unrouted.01
- a queue bound tosys.ex.auditunrouted
q.type1
- a queue that gets 'type1' messages fromex.router.main
q.type2
- a queue that gets 'type2' messages fromex.router.main
...
- unroutedMessagePolicy - applies to all Exchanges starting with 'ex.router'. If the message is unouted unrouted by the Exchange, it will be sent to the 'alternate exchange' :
sys.ex.unrouted
- messageTimeoutPolicy - applies to all Queues starting with 'q'. If the message is left unprocessed on the Queue after 30 seconds, it will be sent to the 'dead-lettter-exchange' :
sys.ex.dead.letter
.
Notes about the Demo configuration
The naming of resources is important - this ensures application Queues and Exchanges are separated out from System Queues and Exchanges. For example messages on the sys
...
.q.dead.letter.01
don't have a TTL but those on q.type1
and q.type2
do.
We've had to use 2 exchanges ex.entry.point
and ex.router.main
. The reason for this is that if have a single exchange from which we copy every message to audit - this will stop messages from appearing unrouted even if they only go to the audit queue.
The functionality covered by the 2 policies could be defined on each Queue/Exchange but this is easy to get wrong. Using policies reduces overhead and increases quality.
Instructions for setting up the demo and exploring its features
...
- other exchanges start with "ex". This naming pattern is important because of the Policies which apply extra functionality to groups of Queues/Exchanges.
Code Block | ||
---|---|---|
| ||
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list exchanges | grep -v amq | grep -v direct +--------------------+---------+ | name | type | +--------------------+---------+ | ex.entry.point | fanout | | ex.router.main | topic | | sys.ex.audit | fanout | | sys.ex.dead.letter | fanout | | sys.ex.unrouted | fanout | +--------------------+---------+ |
...
The first 2 are fanout bindings from ex.entry.poin
t to sys.ex.audit
and and ex.router.main
The next 2 are topic bindings from ex.router.main
to q.type1
for routing key 'type1' and q.type2
for routing key 'type2'. Notice - no binding for 'type3'
The last 3 are fanout bindings for each of the 'sys' exchanges to their message queues.
Code Block | ||
---|---|---|
| ||
davidhay@localhost RABBITMQADMIN-DEMO (master) $ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list bindings | grep -v '^| '
+--------------------+----------------------+----------------------+
+--------------------+----------------------+----------------------+
| ex.entry.point | ex.router.main | |
| ex.entry.point | sys.ex.audit | |
| ex.router.main | q.type1 | type1 |
| ex.router.main | q.type2 | type2 |
| sys.ex.audit | sys.q.audit.01 | |
| sys.ex.dead.letter | sys.q.dead.letter.01 | |
| sys.ex.unrouted | sys.q.unrouted.01 | |
+--------------------+----------------------+----------------------+ |
...
In addition to Exchanges, Queues and Bindings - this demo relies on 2 Routing "Policies". These help provide extra routing for unprocessed and unrouted messages to groups of Exchanges/Queues.
The policy 'unroutedMessagePolicy' applies to exchanges starting with 'ex.router' - any unrouted message gets sent to 'sys.ex.unrouted
'
The policy 'messageTimeoutPolicy' applies to queues starting with 'q' - any message still on a queue after 30seconds 30 seconds is sent to 'sys.ex.dead.letter
'
Note: because of these policies - it's important to name the queues and exchanges carefully.
This shows the 2 policies described abovein the configuration.
Code Block | ||
---|---|---|
| ||
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list policies | grep "^| $VHOST" | vhDemo01 | unroutedMessagePolicy | exchanges | {"alternate-exchange": "sys.ex.unrouted"} | ^ex.router.* | 0 | | vhDemo01 | messageTimeoutPolicy | queues | {"message-ttl": 30000, "dead-letter-exchange": "sys.ex.dead.letter"} | ^q.* | 1 | |
...
It should be on q.type1
and a copy of on sys.q.audit.01
. This demonstrates routing based on message type and auditing.
...
If we wait 30 seconds and check again. The message should timeout on q.type1
and be sent to sys.q.dead.letter.01.
This demonstrates the messageTimeoutPolicy.
Code Block | ||
---|---|---|
| ||
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list queues +----------------------+----------+ | name | messages | +----------------------+----------+ | q.type1 | 0 | | q.type2 | 0 | | sys.q.audit.01 | 1 | | sys.q.dead.letter.01 | 1 | | sys.q.unrouted.01 | 0 | +----------------------+----------+ |
...
It should be on q.type2
and a copy of on sys.q.audit.01
. This demonstrates routing based on message type and auditing.
...
If we wait 30 seconds and check again. The message should timeout on q.type2
and be sent to sys.q.dead.letter.01.
This demonstrates the messageTimeoutPolicy.
Code Block | ||
---|---|---|
| ||
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list queues +----------------------+----------+ | name | messages | +----------------------+----------+ | q.type1 | 0 | | q.type2 | 0 | | sys.q.audit.01 | 2 | | sys.q.dead.letter.01 | 2 | | sys.q.unrouted.01 | 0 | +----------------------+----------+ |
...
The message should end up on sys.q.unrouted.01
because because when it arrived at ex.router.main
there is no mapping for 'type3' messages so it gets sent to sys.ex.unrouted
which forwards to sys.q.unrouted.01.
This demonstrates the unroutedMessagePolicy.
...