我使用Docker将JMS服务器容器链接到另一个JMS客户端容器。但是当我在docker容器中运行服务器时,客户端无法正确连接到服务器。我在docker上公开了端口443(JMS使用的还有其他端口吗?)
我可以成功创建目标,但不能创建JMS上下文:
String PROVIDER_URL = "https-remoting://MYDOMAIN:443";
...
/** PASSED **/
Destination destination = (Destination) namingContext.lookup(destinationString);
/** HAS ERROR **/
JMSContext context = connectionFactory.createContext(username, password)
这是错误:
java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Net.java:123)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:621)
at io.netty.channel.socket.nio.NioSocketChannel.doConnect(NioSocketChannel.java:176)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.connect(AbstractNioChannel.java:169)
at io.netty.channel.DefaultChannelPipeline$HeadHandler.connect(DefaultChannelPipeline.java:1008)
at io.netty.channel.DefaultChannelHandlerContext.invokeConnect(DefaultChannelHandlerContext.java:495)
at io.netty.channel.DefaultChannelHandlerContext.connect(DefaultChannelHandlerContext.java:480)
at io.netty.channel.ChannelOutboundHandlerAdapter.connect(ChannelOutboundHandlerAdapter.java:47)
at io.netty.channel.CombinedChannelDuplexHandler.connect(CombinedChannelDuplexHandler.java:168)
at io.netty.channel.DefaultChannelHandlerContext.invokeConnect(DefaultChannelHandlerContext.java:495)
at io.netty.channel.DefaultChannelHandlerContext.connect(DefaultChannelHandlerContext.java:480)
at io.netty.channel.ChannelDuplexHandler.connect(ChannelDuplexHandler.java:50)
at io.netty.channel.DefaultChannelHandlerContext.invokeConnect(DefaultChannelHandlerContext.java:495)
at io.netty.channel.DefaultChannelHandlerContext.connect(DefaultChannelHandlerContext.java:480)
at io.netty.channel.DefaultChannelHandlerContext.connect(DefaultChannelHandlerContext.java:465)
at io.netty.channel.DefaultChannelPipeline.connect(DefaultChannelPipeline.java:847)
at io.netty.channel.AbstractChannel.connect(AbstractChannel.java:199)
at io.netty.bootstrap.Bootstrap$2.run(Bootstrap.java:165)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:745)
Exception in thread "main" javax.jms.JMSRuntimeException: Failed to create session factory
at org.hornetq.jms.client.JmsExceptionUtils.convertToRuntimeException(JmsExceptionUtils.java:98)
at org.hornetq.jms.client.HornetQConnectionFactory.createContext(HornetQConnectionFactory.java:149)
at org.hornetq.jms.client.HornetQConnectionFactory.createContext(HornetQConnectionFactory.java:130)
at com.wpic.uptime.Client.main(Client.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: javax.jms.JMSException: Failed to create session factory
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:673)
at org.hornetq.jms.client.HornetQConnectionFactory.createContext(HornetQConnectionFactory.java:140)
... 7 more
Caused by: HornetQNotConnectedException[errorType=NOT_CONNECTED message=HQ119007: Cannot connect to server(s). Tried with all available servers.]
at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:905)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:669)
... 8 more
答案 0 :(得分:6)
我刚刚找到了解决这个问题的方法。我也经历过它。
在您的情况下,问题出在JBoss配置中。就我而言,问题出在Wildfly 8.2中。
您可能在JBoss中使用以下参数: jboss.bind.address = 0.0.0.0
我在wildfly中使用此参数让他接受来自任何IP的外部连接,因为我的Wildfly暴露在互联网上。
问题是,如果你没有指定JBon / Wildfly设置HornetQ应该向正在进行远程插件的JMS客户端报告哪个IP,HornetQ将假设IP是在jboss.bind.address中设置的。在这种情况下,0.0.0.0不是有效的IP。您可能在其日志JBoss中看到以下消息:
INFO [org.hornetq.jms.server](ServerService线程池 - 53) HQ121005:检测到“http-connector”的“主机”值“0.0.0.0”无效 连接器。切换到“hostname.your.server”。如果这个新地址是 不正确请手动配置连接器使用正确 之一。
在这种情况下,HornetQ将使用机器名称中定义的主机。例如,在linux上,它将使用/ etc / hostname。
中定义的内容还有另一个问题。因为通常主机名不是Internet上的有效主机,所以可以通过DNS服务解析为IP。
然后注意你可能发生的事情:你的JBoss服务器被安排给0.0.0.0绑定,你的HornetQ(嵌入在JBoss中)试图获取这个IP以及它是如何不是一个有效的IP他正在采取您的服务器的主机名。当您的远程JMS客户端(在您的本地网络之外)在您的JBoss上进行插件时,HornetQ向客户端报告他必须在主机YOUR_HOSTNAME_LOCAL_SERVER上寻找HornetQ资源但是当它尝试通过DNS解析此名称时他不能然后发生以下故障:
java.nio.channels.UnresolvedAddressException at sun.nio.ch.Net.checkAddress(Net.java:123) at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:621) 在io.netty.channel.socket.nio.NioSocketChannel.doConnect(NioSocketChannel.java:176) at io.netty.channel.nio.AbstractNioChannel $ AbstractNioUnsafe.connect(AbstractNioChannel.java:169) at io.netty.channel.DefaultChannelPipeline $ HeadHandler.connect(DefaultChannelPipeline.java:1008) at io.netty.channel.DefaultChannelHandlerContext.invokeConnect(DefaultChannelHandlerContext.java:495) 在io.netty.channel.DefaultChannelHandlerContext.connect(DefaultChannelHandlerContext.java:480) 在io.netty.channel.ChannelOutboundHandlerAdapter.connect(ChannelOutboundHandlerAdapter.java:47) at io.netty.channel.CombinedChannelDuplexHandler.connect(combinedChannelDuplexHandler.java:168) at io.netty.channel.DefaultChannelHandlerContext.invokeConnect(DefaultChannelHandlerContext.java:495) 在io.netty.channel.DefaultChannelHandlerContext.connect(DefaultChannelHandlerContext.java:480) at io.netty.channel.ChannelDuplexHandler.connect(ChannelDuplexHandler.java:50) at io.netty.channel.DefaultChannelHandlerContext.invokeConnect(DefaultChannelHandlerContext.java:495) 在io.netty.channel.DefaultChannelHandlerContext.connect(DefaultChannelHandlerContext.java:480) 在io.netty.channel.DefaultChannelHandlerContext.connect(DefaultChannelHandlerContext.java:465) at io.netty.channel.DefaultChannelPipeline.connect(DefaultChannelPipeline.java:847) at io.netty.channel.AbstractChannel.connect(AbstractChannel.java:199) at io.netty.bootstrap.Bootstrap $ 2.run(Bootstrap.java:165) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354) 在io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353) at io.netty.util.concurrent.SingleThreadEventExecutor $ 2.run(SingleThreadEventExecutor.java:101) 在java.lang.Thread.run(Thread.java:745)
该问题的解决方案是配置JBoss哪个主机应该通知远程客户端的客户。
在我的情况下,野生蝇的设置如下。必须更改standalone.xml文件:
<subsystem xmlns="urn:jboss:domain:messaging:2.0">
<hornetq-server>
<security-enabled>true</security-enabled>
<journal-file-size>102400</journal-file-size>
<connectors>
<http-connector name="http-connector" socket-binding="http-remote-jms">
<param key="http-upgrade-endpoint" value="http-acceptor"/>
</http-connector>
</connectors>
...
</hornetq-server>
</subsystem>
和
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
...
<outbound-socket-binding name="http-remote-jms">
<remote-destination host="YOUR_REAL_HOSTNAME" port="${jboss.http.port:8080}"/>
</outbound-socket-binding>
</socket-binding-group>
请注意,我没有使用https,因为我无法使用https for JMS。