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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With