Skip to content
Advertisement

spring-jms – listener exchange and bind queue by jms configuration

I have a project with spring-jms

I’m trying work with exchanges. I created 4 listeners and all of them are been bound into exchange named ‘jms.durable.queues’ by default. Even thought I create my own exchanges and binding my queues manually on rabbit console, spring is creating a default exchange.

How could I create my own queues and bind into my exchanges or disable spring to create queues and bind into default exchange ‘jms.durable.queues’?

My configuration class

JavaScript

My listeners

JavaScript

dependencies

JavaScript

I have seen about RMQDestination.class, can I use it to create my two exchange and queues? Is there any spring resolver to manager destination programatically on spring-jms configuration?

example as pseudo-code

JavaScript

Advertisement

Answer

See source code of this class in RabbitMQ JMS Client: https://github.com/rabbitmq/rabbitmq-jms-client/blob/main/src/main/java/com/rabbitmq/jms/admin/RMQDestination.java.

Since you don’t provide an exchange explicitly that queue name is really bound to that default exchange.

See more docs about this JMS client and how to declare destinations manually for specific exchange and binding : https://www.rabbitmq.com/jms-client.html.

UPDATE

See that documentation closer: https://www.rabbitmq.com/jms-client.html#destination-interoperability

JavaScript

Then look into @JmsListener JavaDocs:

JavaScript

The JmsDestinationAccessor uses a DynamicDestinationResolver by default, which, probably, is not going to work over here for us since it is going to do whatever you have so far with that jms.durable.queues exchange.

So, another option to consider for your solution is the custom:

JavaScript

So, you need to add a bean for the DefaultJmsListenerContainerFactory and inject into its setDestinationResolver(DestinationResolver) a BeanFactoryDestinationResolver. Then you provide a RMQDestination bean name into that destination option of your @JmsListener method and BeanFactory is going to give you a proper RMQDestination with desired exchange and binding.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement