我需要通过Mule订阅JMS主题。我们正在使用Mule 3.5
我已设置此流程:
<jms:connector name="vos-jms-connector" specification="1.1"
validateConnections="true"
connectionFactoryJndiName="ConnectionFactory"
doc:name="JMS" password="guest" username="guest">
<jms:custom-jndi-name-resolver
class="org.mule.transport.jms.jndi.CachedJndiNameResolver">
<spring:property name="jndiInitialFactory"
value="org.jnp.interfaces.NamingContextFactory" />
<spring:property name="jndiProviderUrl" value="jnp://xx.xx.16.41:1099" />
</jms:custom-jndi-name-resolver>
</jms:connector>
<flow name="vcm-vos-vpo-topic" doc:name="vcm-vos-vpo-topic">
<jms:inbound-endpoint topic="VPOtopic"
connector-ref="vos-jms-connector" doc:name="VPOtopic" responseTimeout="4000" />
<logger message="request for topic" level="INFO" doc:name="Logger"/>
</flow>
当我运行Mule项目时,我希望我可以使用以下java代码连接到该主题(这在另一个项目中,在同一台机器上运行):
Properties props = new Properties();
props.setProperty(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
InitialContext context = new InitialContext(props);
TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory");
Topic vpoTopic = (Topic) context.lookup("VPOtopic");
然而,我得到了“Coneection Refused”例外:
Exception in thread "main" javax.naming.CommunicationException: Could not obtain connection to any of these urls: 127.0.0.1:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server /127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server /127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]]
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1828)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:717)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:710)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at nl.triopsys.vcm.vos.jmsmock.Main.getInitialContext(Main.java:132)
at nl.triopsys.vcm.vos.jmsmock.Main.main(Main.java:65)
Caused by: javax.naming.CommunicationException: Failed to connect to server /127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server /127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:359)
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:284)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1798)
... 5 more
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server /127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:329)
... 7 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:97)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:82)
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:325)
... 7 more
如何连接到localhost上的入站端点?
答案 0 :(得分:0)
您实际使用的是JNDI服务吗? 简而言之,您不需要在主题属性上设置全名,只需使用名称:
虽然从主题中读取并写入同一主题是很奇怪的。