1
votes

Am trying to consume the message from exiting queue which is of type Direct Exchange(created with the help of exchange and routing key). I have only the exchange name and routing key and not the queue name. There were support for plain Java, but there was no place where I can find it for Spring boot.

@RabbitListener
    @RabbitHandler
    public void consumeMessage(Object message) {
        LOGGER.debug("Message Consumed.... : {}", message.toString());
    }

How can I consume messages with routing key and exchange name not the queue name as @RabbitListener asks for queue.

1
With a direct exchange, the routing key is the queue name.theMayer
@theMayer @RabbitListener(queues = "${routing.key}") @RabbitHandler public void consumeMessage(Object message) { LOGGER.debug("Message Consumed.... : {}", message.toString()); } This is giving a exception 404 - reply-code=404, reply-text=NOT_FOUND - no queueSASIKUMAR S
Have you declared the queue?theMayer

1 Answers

1
votes

Consumers consume from queues not exchanges. You must bind a queue to the exchange with the routing key.

EDIT

There are several ways to automatically declare a queue on the broker.

    @RabbitListener(bindings = 
        @QueueBinding(exchange = @Exchange("myExchange"), 
            key = "myRk", value = @Queue("")))
    public void listen(String in) {
        System.out.println(in);
    }

This will bind an anonymous queue (auto-delete) which will be deleted when the application is stopped.

    @RabbitListener(bindings = 
        @QueueBinding(exchange = @Exchange("myExchange"), 
            key = "myRk", value = @Queue("foo")))
    public void listen(String in) {
        System.out.println(in);
    }

Will bind a permanent queue foo to the exchange with the routing key.

You can also simply declare #Bean s for the queue, exchange and binding.

See Configuring the broker.