NWard
NWard

Reputation: 2086

Is there a way to specify "not matching" in an AMQP routing key?

I'm building a system using RabbitMQ. One of the things I want to be able to do is direct log messages to different queues based on the severity of the message that's being logged. Errors and exceptions should go to one queue for immediate handling; less-important messages like Trace logs should go somewhere else, so they don't clog up critical logging.

The way I thought to handle this is to set up a Topic exchange and bind two queues to the exchange. Then, my log messages will use their log level in the routing key to get sent to the right queue. However, I have a problem where I don't know the best way to set up the routing keys.

Getting my errors into the right queue is easy - bind two queues to the exchange, one with an Error routing key, and then messages with an Error routing key get sent to it. I want every other kind of message sent to this exchange to go to the other queue. But I don't think you can describe a routing key like !Error or something, or at least it doesn't appear in the RabbitMQ tutorials or the AMQP spec that I can see. If I use a wildcard binding, then my error messages get delivered to both queues.

It looks like I can accomplish this by using an Alternate Exchange (http://www.rabbitmq.com/ae.html) But I would rather stick with straight AMQP if possible, and configuring AEs adds another layer of complexity to my system initialization.

I could also define routing keys for every log level in my system, and explicitly route everything that isn't Error to the low-level queue. But that seems excessively verbose and adds maintenance overhead.

Is there a better way to accomplish my goal than using an AE?

Upvotes: 2

Views: 2653

Answers (1)

Luca Ghersi
Luca Ghersi

Reputation: 3321

Basically the answer is no, is not possibile with the routing key; it's just a "match" thing, not a regex or similar.

What about routing Error on one side, and everything (including error) on the other side? I mean, I suppose you will have less error messages than trace messages (I hope, at least); you will have to "skip" them business side, but I think it will be easier to manage than a RabbitMQ extension.

PS: The nearest thing I can come out with is the Topic Exchange, but it will suffer of the same limitation. Check this for more documentation. PPS: There is also this other SO answer, if you like.

Hope it helps :)

Upvotes: 2

Related Questions