我已经在Tomcat7中部署了一个应用程序来读取Weblogic 11g中来自Foreign JMS Topic的消息。这是我的spring应用程序上下文xml。我在我的类路径中包含了wlthint3client.jar。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Uncomment and add your base-package here: <context:component-scan base-package="org.springframework.samples.service"/> -->
<tx:jta-transaction-manager/>
<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager" p:connectionFactory-ref="clarifyconnectionFactory"/>
<bean id="clarifyTopic" class="org.springframework.jndi.JndiObjectFactoryBean"
p:jndiName="jms/ATomcatClarifyTopic"
p:proxyInterface="javax.jms.Destination"
p:jndiTemplate-ref="jndiTemplate"/>
<bean id="messageAdapter" class="org.springframework.jms.listener.adapter.MessageListenerAdapter" p:defaultListenerMethod="receive">
<constructor-arg>
<bean class="com.jnpr.clarify.jms.DefaultTextMessageDelegate"/>
</constructor-arg>
</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://weblogichost:8001</prop>
</props>
</property>
</bean>
<!-- Lookup JMS Connection Factory -->
<bean id="clarifyconnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"
p:jndiName="jms/TestTopicConnectionFactory" p:proxyInterface="javax.jms.TopicConnectionFactory"
p:jndiTemplate-ref="jndiTemplate"
p:exposeAccessContext="true"/>
<!-- Configuring JMS Template -->
<bean id='jmsTemplate' class="org.springframework.jms.core.JmsTemplate"
c:_0-ref="clarifyconnectionFactory" />
<!-- Configuring Topic Listener -->
<bean id="topicListener" class="com.jnpr.clarify.jms.TopicListener" />
<!-- Configuring MessageListenerContainer -->
<bean id="JMSMessageListenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer"
p:destination-ref="clarifyTopic" p:connectionFactory-ref="clarifyconnectionFactory"
p:messageListener-ref="messageAdapter" p:transactionManager-ref="jmsTransactionManager"
p:durableSubscriptionName="TomcatClarify"/>
</beans>
我在tomcat服务器日志中遇到异常。
警告:JMS消息侦听器调用程序的设置失败,目的地为“JUN_JMS_SOA_Module!ATomcatClarifyTopic” - 尝试恢复。原因:[JMSClientExceptions:055142]外部目的地,JMS_SOA_Module!TomcatClarifyTopic Jan 01,2015 7:09:13 PM org.springframework.jms.listener.DefaultMessageListenerContainer refreshConnectionUntilSuccessful 信息:成功刷新JMS连接
如果我做错了,请帮忙。
答案 0 :(得分:0)
当使用jms命名空间配置消息监听器容器而不是常规spring bean时,上面的代码工作。
<jms:listener-container container-type="default" acknowledge="auto"
connection-factory="clarifyconnectionFactory" destination-type="durableTopic"
destination-resolver="jmsDestinationResolver">
<jms:listener destination="jms/ATomcatClarifyTopic" ref="topicListener"/>
</jms:listener-container>
<bean id="jmsDestinationResolver"
class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="cache">
<value>true</value>
</property>
</bean>