Connection Factories and JMS Destinations

The JmsTemplate class handles all of the logic for connecting to a JMS provider and accessing the JMS destinations. However, you still need to specify how the JmsTemplate class establishes the connection to the JMS provider. There are two ways to do this; using JNDI, or using the native connection factories and destination classes supplied by the provider. This section will go through the details of both of these methods, starting with JNDI.

Using JNDI

Spring provides several classes within its messaging framework for accessing JNDI-based connection factories and destinations. The advantage of this approach is that using JNDI further decouples your application from the JMS provider. The Spring classes needed when using JNDI to access the connection factories and JMS destinations are the JndiTemplate, JndiObjectFactoryBean, CachingConnectionFactory (or SingleConnectionFactory), JndiDestinationResolver, and finally the JmsTemplate. The relationship between these Spring classes and the JMS template is shown in Figure 9-4.

JNDI objects and the JmsTemplate

Figure 9-4. JNDI objects and the JmsTemplate

The first thing you need to do is define the JndiTemplate bean, which is used to specify the initial context factory, provider URL, and security credentials necessary to make a connection to the JMS provider. It is here that you would specify the TCP address and port for the JMS provider ...

Get Java Message Service, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.