Question

I am new to Spring Jms and i studied how to work with spring and jboss to create queues and work with them. I want to know how queues are created when configured with JndiObjectFactoryBean spring configuration.

Do we need to write some xml configurations for creating Queues?.I have seen various examples of writing queue configurations in file and placing in deploy folder of jboss.So when working with Spring do we need to write those configurations?

Please Help me i am stuck.

Thank you.

Was it helpful?

Solution

When you work with a JMS broker that is accessed through JNDI, you only need to make sure that Spring is going to be able to resolve a String representing the javax.jms.Destination to the actual Destination.

Spring does that with DestinationResolver. Since you have configured Spring to connect to your JMS broker, you must have a JNDI configuration somewhere (either through the use of jndi.properties or some other form). And you can easily create a JndiTemplate with it if that's not the case already

Once you have that, you need to define a bean as follows, assuming the JndiTemplate bean is available with name jndiTemplate:

@Bean
public JndiDestinationResolver destinationResolver() {
   JndiDestinationResolver destinationResolver = new JndiDestinationResolver();
   destinationResolver.setJndiTemplate(jndiTemplate());
   return destinationResolver;
}

or

<bean id="destinationResolver"
      class="org.springframework.jms.support.destination.JndiDestinationResolver">
    <property name="jndiTemplate" ref="jndiTemplate"/>
</bean>

Then you need to configure this destinationResolver instead of the default. You can do that on JmsTemplate and on the message listener container (check the destinationResolver or destination-resolver property).

The name of your queue or topic is the jndi entry. Chekc the JNDI name that you have used in JBoss to lookup it from your Spring-based code.

OTHER TIPS

When you work with some JEE container it would be better, if you rely on its options: JDBC, JMS etc. Hance in your case you should configure Queue and ConnectionFactory using JBOSS configuration.

From Spring application you just need to get reference to those objects from JNDI. Seems for like @Resource should be enough for case of @Configuration or any @Component service.

Here is some answer how to configure Spring to get deal with JNDI in case of Annotation configuration: Spring @Resource Handling

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top