[rabbitmq-discuss] custom exchange
Simon MacMullen
simon at rabbitmq.com
Thu May 31 10:56:31 BST 2012
On 31/05/12 07:34, Sujan Dutta wrote:
> Now my requirement is that - Add a custom header to the every messages
> which is delivered through the custom exchange.
I'm afraid there isn't a general API for that.
The problem is that exchanges are just for routing - in a complex
exchange-to-exchange scenario where a message gets routed like:
/--> X2 --\
| v
X1 X4 --> Q
| ^
\--> X3 --/
only one copy of the message ends up in Q - so did it pass through X2 or
X3? Which one has the right to modify it?
Having said that, if you know that you *won't* be using such complex
routing, you could do this by:
route(X, Delivery) ->
case custom_header_exists(Delivery) of
true -> route_as_normal(Delivery);
false -> rabbit_basic:publish(X, add_custom_header(Delivery)),
[]
end.
i.e. if the header needs to be added, don't route it at all, but instead
republish it to yourself with the header added.
Cheers, Simon
--
Simon MacMullen
RabbitMQ, VMware
More information about the rabbitmq-discuss
mailing list