I'm new in RabbitMQ and I want to modify a message before consuming it by a queue. I have an exchange which should stay untouchable. The client receives messages with a specific routing key. But there a lot of them and I want to filter and change body before publishing them into queue.
Exchange populate messages looks like:
{
"_context_domain": "unsuitable",
"_msg_id": "1",
"_context_quota_class": null,
"_context_read_only": false,
"_context_request_id": "1"
}
{
"_context_domain": "suitable",
"_msg_id": "2",
"_context_quota_class": null,
"_context_read_only": false,
"_context_request_id": "2"
}
Is there any way to filter and modify them before consuming? For example:
...
channel.queueBind(QUEUE_NAME, "EXCHANGE_NAME", "ROUTNG_KEY");
final Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
String message = new String(body, "UTF-8");
Gson mapper = new Gson();
SomeObject object = (SomeObject) mapper.fromJson(message, SomeObject.class);
if (SomeObject.getContext_domain = "suitable"){
//publish somehow SomeObject.getMsg_id into QUEUE_NAME
}
}
Is there any way to do it?