how to configure jms template at spring for weblogic? - spring

as my question title, how to configure jms template at spring for weblogic?
i follow an example at some website, but spring always complain about defaultDestination at JmsTemplate
how to configure it correctly ?
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">t3://localhost:7001</prop>
</props>
</property>
</bean>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="jndiName" value="jms/confactory" />
</bean>
<bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="cache" value="true" />
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destinationResolver" ref="jmsDestinationResolver" />
</bean>
nb : i use weblogic 9.2 for jms & web server, spring 2.5.6

i find out, that destination should contain jms destination
<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jms/queue" />
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destinationResolver" ref="jmsDestinationResolver" />
<property name="defaultDestination" ref="destination" />
<property name="sessionAcknowledgeModeName" value="CLIENT_ACKNOWLEDGE"/>
<property name="sessionTransacted" value="true" />
</bean>

Related

Message driven POJO with spring. Can't receive the message

my application deployed on Tomcat am I am trying to send and receive message from remote queue.
I already have succeeded to send few messages to remote queue. Now I am trying to build message listener container, however my onMessage(method is never called), don't understand what I am missing.
This is my configuration
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destinationResolver" ref="destinationResolver" />
</bean>
<bean id="connectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="targetConnectionFactory"/>
<property name="username" value="user"/>
<property name="password" value="pass"/>
</bean>
<bean id="targetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="jndiName" value="MY_TEST_QUEUE" />
<property name="proxyInterface" value="javax.jms.ConnectionFactory"/>
</bean>
<bean id="destinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="cache" value="true" />
</bean>
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">t3://host:port</prop>
</props>
</property>
</bean>
<bean id="messageListener" class="com.package.MyCustomMDB" />
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="destinationName" value="MY_TEST_QUEUE"/>
<property name="destinationResolver" ref="destinationResolver" />
<property name="messageListener" ref="messageListener" />
</bean>
And implementation of mdb
public class MyCustomMDB implements MessageListener {
#Override
public void onMessage(Message message) {
System.out.println(message.toString());
}}
Could you please advise me where I am doing something wrong?
You are using MY_TEST_QUEUE for the both the jndiName of targetConnectionFactory and destinationName of jmsContainer. The the jndiName of targetConnectionFactory should refer to the name of a connection factory rather than a queue.

How to listen jms-queue from remote server

i have implemented jms queue and listner in spring application.
I am not able to listen jms queue from remote system. I have configured Queue in server application util-sevice.xml file.
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.provider.url">http-remoting://182.18.177.115:80</prop>
<prop key="java.naming.factory.initial">org.jboss.naming.remote.client.InitialContextFactory
</prop>
<prop key="java.naming.security.principal">user</prop>
<prop key="java.naming.security.principal">pwd</prop>
</props>
</property>
</bean>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName" value="jms/RemoteConnectionFactory">
</property>
</bean>
<bean id="credentialsconnectionfactory"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="connectionFactory" />
<property name="username" value="use" />
<property name="password" value="pwd" />
</bean>
<bean id="genricDbSyncDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="jndiName" value="java:/jms/queue/GenricDbSyncQueue" />
</bean>
<bean id="genricDbSyncTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="credentialsconnectionfactory" />
<property name="defaultDestination" ref="genricDbSyncDestination" />
</bean>
standalone-full.xml in remote server
<jms-queue name="GenricDbSyncQueue">
<entry name="jms/queue/GenricDbSyncQueue"/>
<entry name="java:jboss/exported/jms/queue/GenricDbSyncQueue"/>
</jms-queue>
and my local system spring application util-service.xml config file for listening that queue
<bean id="genricDbSyncListener" class="com.ayotta.genericdbsync.GenericDbSyncConsumer" />
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.provider.url">http-remoting://182.18.177.115:80</prop>
<prop key="java.naming.factory.initial">org.jboss.naming.remote.client.InitialContextFactory
</prop>
<property name="username" value="use" />
<property name="password" value="pwd" />
</props>
</property>
</bean>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName" value="jms/RemoteConnectionFactory">
</property>
</bean>
<bean id="credentialsconnectionfactory"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="connectionFactory" />
<property name="username" value="use" />
<property name="password" value="pwd" />
</bean>
<jms:listener-container connection-factory="credentialsconnectionfactory"
concurrency="1" acknowledge="auto" destination-type="queue">
<jms:listener destination="GenricDbSyncQueue" ref="genricDbSyncListener"
method="onMessage" />
</jms:listener-container>
How to listen that remote jms queue from local system application

WebLogic 10.3.6 throws JMSClientExceptions:055142 when configured with lookupOnStartup false

I have simple Java Spring application which looks up JMS objects using JNDI and publishes a message to a JMS Topic. JNDI and JMS configured on WebLogic 10.3.6. All this works fine as long as the WebLogic server is up and running.
I need to get the application to start up even when the WebLogic server is down. I have configured the JNDI objects with "lookupOnStartup" as "false".
Below is my Spring configuration.
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">${jndi.initialFactory}</prop>
<prop key="java.naming.provider.url">${jndi.providerurl}</prop>
</props>
</property>
</bean>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>${jms.connectionFactory}</value>
</property>
<property name="lookupOnStartup" value="false" />
<property name="proxyInterface" value="javax.jms.ConnectionFactory" />
</bean>
<bean id="myTopic" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>${jms.mytopic}</value>
</property>
<property name="lookupOnStartup" value="false" />
<property name="proxyInterface" value="javax.jms.Destination" />
</bean>
<bean id="jmsDestinationResolver"
class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="cache" value="true" />
</bean>
<bean id="myTopicTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="defaultDestination" ref="myTopic" />
<property name="destinationResolver" ref="jmsDestinationResolver" />
<property name="connectionFactory" ref="connectionFactory" />
<property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE" />
<property name="sessionTransacted" value="false" />
</bean>
At runtime I get the following exception:
Exception in thread "main" org.springframework.jms.InvalidDestinationException: [JMSClientExceptions:055142]Foreign destination, jmsserver-module!my-topic; nested exception is weblogic.jms.common.InvalidDestinationException: [JMSClientExceptions:055142]Foreign destination, jmsserver-module!my-topic
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:285)
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:169)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:497)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:569)
...
Caused by: weblogic.jms.common.InvalidDestinationException: [JMSClientExceptions:055142]Foreign destination, jmsserver-module!my-topic
at weblogic.jms.common.Destination.checkDestinationType(Destination.java:105)
at weblogic.jms.client.JMSSession.setupJMSProducer(JMSSession.java:2830)
at weblogic.jms.client.JMSSession.createProducer(JMSSession.java:2858)
at weblogic.jms.client.JMSSession.createProducer(JMSSession.java:2822)
at weblogic.jms.client.WLSessionImpl.createProducer(WLSessionImpl.java:827)
at org.springframework.jms.core.JmsTemplate.doCreateProducer(JmsTemplate.java:1143)
at org.springframework.jms.core.JmsTemplate.createProducer(JmsTemplate.java:1124)
at org.springframework.jms.core.JmsTemplate.doSend(JmsTemplate.java:601)
at org.springframework.jms.core.JmsTemplate$3.doInJms(JmsTemplate.java:572)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494)
... 3 more
Any help is much appreciated. Thank you!
In Destination.java:
if(!(destination instanceof DestinationImpl))
throw new InvalidDestinationException
The proxied connectionFactory is not able to resolve the the destination type. I was able to resolve this issue by providing only the destination name to the JmsTemplate and using a JNDI destinationResolver to resolve the destination type on demand. So the modified Spring configuration looks like:
<bean id="myTopicTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="defaultDestinationName">
<value>${jms.mytopic}</value>
</property>
<property name="destinationResolver" ref="jmsDestinationResolver" />
<property name="connectionFactory" ref="connectionFactory" />
<property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE" />
<property name="sessionTransacted" value="false" />

Camel Transaction Configuration Issue: javax.persistence.TransactionRequiredException

I'm configuring JMS Transactions in Camel 2.10.4 routes. When I run my app, a javax.persistence.TransactionRequiredException: no transaction in progress is thrown. From my research, I found out that this exception is thrown when no method is marked #Transactional. The relevant sections in my application context XML config file is shown:
<bean id="txMgr" class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="pooledConnectionFactory" />
</bean>
<bean id="REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="txMgr" />
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED" />
</bean>
<bean id="pooledConnectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
<property name="maxConnections" value="8" />
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig" />
</bean>
<bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="transacted" value="true" />
<property name="transactionManager" ref="txMgr" />
<property name="concurrentConsumers" value="3"/>
</bean>
Besides the JMS-specific configuration, I also have JPA configuration, which is shown below:
<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager">
<bean class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
</property>
</bean>
<bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="fileRecord" />
</bean>
If I disable transactions, the configuration works. When I enable it, however, all the other steps succeeds except the bit where the data is to be inserted into the database (at the JPA endpoint).
Any suggestions on what I need to change or add will be appreciated very much.

Connect to EMS JMS queue using Spring3 + JNDI

I'm having some issues create a connection to (and reading from) a Tibco EMS JMS queue.
<beans>
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">com.tibco.tibjms.naming.TibjmsInitialContextFactory</prop>
<prop key="java.naming.provider.url">tcp://ems-dit-am-uat-1.app.xxx.net:30055</prop>
</props>
</property>
</bean>
<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate" /> <property name="jndiName"
value="DRDRFIQueueConnectionFactory" /> </bean>
<bean id="jmsDestinationResolver"
class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="cache" value="true" />
</bean>
<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="jndiName" value="Q.NY.DERIV.DRD.RFI" />
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="destinationResolver" ref="jmsDestinationResolver" />
<property name="defaultDestination" ref="destination" />
</bean>
<bean id="jmsReceiver" class="com.csfb.fao.rds.rfi.application.DRDReceiverTst">
<property name="jmsTemplate">
<ref bean="jmsTemplate" />
</property>
</bean>
</beans>
The exception I'm getting is:
javax.naming.AuthenticationException: Not permitted: invalid name or
password [Root exception is javax.jms.JMSSecurityException: invalid
name or password] at
com.tibco.tibjms.naming.TibjmsContext.lookup(TibjmsContext.java:668)
at
com.tibco.tibjms.naming.TibjmsContext.lookup(TibjmsContext.java:489)
at javax.naming.InitialContext.lookup(InitialContext.java:392) at
org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at
org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at
org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at
org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at
org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at
org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 12 more
The only user/password I've been given is for the JMS queue itself - where do I set that?
Thanks
Chris
Got it - needed to wrap the connection factory in a UserCredentialsConnectionFactory:
<bean id="authenticationConnectionFactory"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="jmsConnectionFactory" />
<property name="username" value="yyyyy" />
<property name="password" value="xxxx" />
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="authenticationConnectionFactory" />
<property name="destinationResolver" ref="jmsDestinationResolver" />
<property name="defaultDestination" ref="destination" />
I had some similar problem , solution was to add (besides solution from this question)
<prop key="java.naming.security.principal">username</prop>
<prop key="java.naming.security.credentials">password</prop>
to jndiTemplate bean configuration
I don't have any experience with EMS, but user and password are typically set on the connection factory, so you'd want to configure that on the object being provided by JNDI.

Resources