8
votes

I'm working on a Java application which uses Spring Boot version 2.0.4.RELEASE and RabbitMQ version 3.7.7. The app is caching all the messages from the RabbitMQ in Redis database and has to resend when a new Queue is created in RabbitMQ. Currently, I managed to capture the Queue creation using Event Exchange Plugin and also the Queue name. I am using AMQP outbound adapter to send the messages back to RabbitMQ.

OutFlow

public IntegrationFlow outFlow(AmqpTemplate amqpTemplate) {
    return IntegrationFlows.from(outputChannel())
            .handle(Amqp.outboundAdapter(amqpTemplate)
                    .routingKeyExpression("headers.routingKey")
                    .exchangeNameExpression("headers.exchange"))
            .get();
}

I can send the messages to specific exchange with the routingKey. But, I don't know how to configure the Queue name in the outbound adapter. So that I can send the message to that specific Queue.

1
IIRC, mapping routingKeys to queues is something that you configure in the RabbitMQ server, not in the sender... So the sender only needs to know what the proper routingKey is they should use, and the actual queue is hidden "behind" the exchange ... - moilejter
yes, the sender only needs to know 'routingKey' and 'exchangeName'. In my scenario, I need to send to a specific Queue, rather than all Queues linked to that particular exchange. If possible I am happy to send the messages straight to the Queue bypassing the exchange. - Vimal David
But you can configure the RabbitMQ exchange to "know" to route a particular routingKey to a specific queue - then your client, by choosing the right routingKey, would see its messages end up in the right queue... - moilejter
Yes, we could bind the exchange to the Queue using 'routingKey'. Unfortunately, my specification asked not to create Queues in prior. So a new Queue is created by RabbitMQ when a new client connects and subscribe to the message. So there could be multiple Queues bind to one exchange. But, When a new Queue is created I want to send messages to that particular Queue, rather than all Queues bind to that exchange. - Vimal David
Don't you just want to create a routing key for each queue, as you register them, then somehow share those keys with all clients? That way, they would use the right routing key for the right queue, and the exchange would deliver it to the corresponding queue? - moilejter

1 Answers

0
votes

If you want to send to the specific queue, use the queue name for the routing key and default global exchange - empty name. There is one special direct exchange which has all the queue bound to it by their names as routing keys.

See AMQP protocol docs for more info: https://www.rabbitmq.com/tutorials/amqp-concepts.html#exchange-default