0

I'm working on sending and receiving messages to/from an IBM MQ queue using JmsTemplate. My application is installed on a WebSphere application server 8.0 and, in order to retrieve the connection, I use a jndi lookup.

I have 6 queues from where I need to pick/drop xmls depending on scenarios. Also I have added these queue in WAS. I need help to understand two things:

  1. I should use DynamicDestinationResolver or JndiDestinationResolver?

  2. As per my understanding I should use JndiDestinationResolver; if that is right how I can define that in my context file and refer jndi-lookup for each queue so that I can retrieve it from my code while using jmsTemplate send/receive?

Please see below my application context file:

<bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> 
<property name="jndiName" value="jms/CPC.TapQueueConnCPC" /> 
<property name="lookupOnStartup" value="false" /> 
<property name="cache" value="true" /> 
<property name="proxyInterface" value="javax.jms.QueueConnectionFactory" /> 
</bean> 
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsQueueConnectionFactory" />
<property name="receiveTimeout" value="10000" /> 
<property name="sessionAcknowledgeMode" value="1" /> 
<property name="destinationResolver" ref="jmsDestResolver"/>
</bean>
<bean id="fileTransferServiceImpl" class="org.kp.cpc.service.FileTransferServiceImpl" > 
<constructor-arg name="jmsTemplate" ref="jmsTemplate" />    
</bean>
<bean id="jmsDestResolver" class=" org.springframework.jms.support.destination.JndiDestinationResolver"/>
<jee:jndi-lookup id="drop278" jndi-name="jms/CPC.SEND.AUTHREQ278" />
<jee:jndi-lookup id="drop275" jndi-name="jms/CPC.SEND.AUTHREQ275" />
<jee:jndi-lookup id="recev278" jndi-name="jms/CPC.RECE.AUTHREQ278" />
<jee:jndi-lookup id="recev275" jndi-name="jms/CPC.RECE.AUTHREQ275" />
<jee:jndi-lookup id="preAuthStatus" jndi-name="jms/CPC.RECE.PREAUTH.STSUPD278"/>
<jee:jndi-lookup id="succ278" jndi-name="jms/CPC.RECE.SUCC.AUTHRESP278" />
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Nik
  • 5
  • 1
  • 3
  • The whole point of the `JndiDestinationResolver` is that you don't need the `jee:jndi-lookup`. Your destination would be the JNDI name you want to send it to. If you really want to leave the `jee:jndi-lookup` use the `BeanFactoryDestinationResolver` instead and use the name of the bean as the destination. – M. Deinum Apr 10 '19 at 07:52

1 Answers1

0

The whole point of the JndiDestinationResolver is that you don't need to do manual lookups. In other words when using the JndiDestinationResolver you don't need the <jee:jndi-lookup /> as that is al handled by the DestinationResolver.

The name of the destination would be the JNDI name. So in your JMS code you would use the following.

jmsTemplate.convertAndSend("jms/CPC.SEND.AUTHREQ278", "Your-Message-Here");

The JndiDestinationResolver will use the name of the destination to do a JNDI lookup.

If you really want to keep the JNDI names out of your code and want to use the <jee:jndi-lookup /> then use the [BeanFactoryDestinationResolver]. This will use the name of the destination to lookup a bean from the BeanFactory (in this case the ApplicationContext). Your JMS code would then point to the bean name instead of the JNDI name.

jmsTemplate.convertAndSend("drop278", "Your-Message-Here");

So which one to use depends on your preferences.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
  • Thanks so much for your reply. This answers my question. – Nik Apr 10 '19 at 23:24
  • Is it not required to set the JndiDestinationresolver as the "destinationResolver" property value? Some thing like this... @Bean public JmsTemplate getJmsTemplate() { JmsTemplate template = new JmsTemplate(); template.setConnectionFactory(getFactory()); template.setDeliveryMode(2); template.setMessageConverter(smartMessageConverter); template.setDestinationResolver(jndiDestinationResolver); return template; } – raj240 Dec 13 '19 at 06:09
  • Sorry for the improper format of the code snippet, i was away from my desk for few minutes while editing the comment, and after wards i am unable to edit the comment. – raj240 Dec 13 '19 at 06:17