Check if the Exchange with a specified name exist in rabbitmq

Anand Patel

I have a scenario where there is an application which is generating different types of interesting events (not commands). The producer application does not care about by whom and how the events get processed.

I am implementing a consumer who will listen to few of the published events and process them appropriately. The consumer application wants to check if the publisher application exchange exists or not. So, the question is how to check if exchange with specific name exists or not by making use of spring provided rabbit/AMQP libraries?

I guess, this could be handled indirectly by trying to bind a queue to a non-existing exchange resulting in an exception. I am looking for better way to handle this situation.

Gary Russell

Use passive declaration and a RabbitTemplate; something like...

final String exchange = "foo";
boolean exists rabbitTemplate.execute(new ChannelCallback<DeclareOk>() {
        @Override
        public DeclareOk doInRabbit(Channel channel) throws Exception {
            try {
                return channel.exchangeDeclarePassive(exchange);
            }
            catch (Exception e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Exchange '" + exchange + "' does not exist");
                }
                return null;
            }
        }
    }) != null;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

RabbitMQ using Direct Exchange when Topic was specified

Check if name already exist

Check if database with specified name exists or not

Rabbitmq cluster, How to find a node from queue or exchange name?

How to use current exchange and queue name of rabbitmq with spring cloud stream rabbitmq

RabbitMQ bind exchange to exchange in bash

How to check that all predicates of a specified name have the specified number of arguments?

Jquery Validator, Check if input name is exist in array or not

how to check if a name exist multiple times in an array

Check if object exist in collection with only name

check field name of db exist string

How to check if 'name' exist in multiple table?

How to handle errors when RabbitMQ exchange doesn't exist (and messages are sent through a messaging gateway interface)

How to check if specified id does not exist in two tables in MySQL?

Check whether exist the database object with the specified field values

ng g c c-name => Specified module does not exist

Default rabbitmq exchange type

RabbitMQ Exchange exclude queue

Why declare Exchange in RabbitMQ?

RabbitMQ bind exchange in Python

RabbitMQ Exchange with catch all

How can I check exchange, queue and topics in QPID like Rabbitmq does?

Bind rabbitmq default exchange to other exchange

Check whether class instance variable with same name as specified function is None or not

Excel: check multiple cells for specified values, name the ones that do not match

Check whether a specified XML element have certain name using JAVA

How to check if a file or directory exist in a system by name using Java

Check if name already exist in database but Id is not same in Laravel 6

Check if a given service name exist or not and its status with NSSM API