本文介绍了使用HornetQ(JBoss)在Docker容器上公开的JMS所需的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Docker将JMS服务器容器链接到另一个JMS客户端容器。但是当我在Docker容器中运行服务器时,客户端无法正确连接到服务器。我在Docker上露出443端口(JMS是否还有任何其他端口?)



我可以成功创建命令,而不是JMS上下文:

  String PROVIDER_URL =https-remoting:// MYDOMAIN:443; 
...

/ ** PASSED ** /
目标目标=(目标)namingContext.lookup(destinationString);

/ ** HAS ERROR ** /
JMSContext context = connectionFactory.createContext(username,password)

这是错误:

  java.nio.channels.UnresolvedAddressException 
在sun.nio.ch.Net.checkAddress(Net.java:123)
在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)
at io.netty.channel.DefaultChannelHandlerContext.connect(DefaultChannelHandlerContext.java :480)
at io.netty.channel.ChannelOutboundHandlerAdapter.connect(ChannelOutboundHandlerAdapter.java:47)
在io.netty.channel.CombinedChannelDuplexHandler.connect(CombinedChannelDuplexHandler.java:168)
在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)
在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)
在io.netty.util.concurrent.Si ngleThreadEventExecutor.runAllTask​​s(SingleThreadEventExecutor.java:354)
在io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
在io.netty.util.concurrent.SingleThreadEventExecutor $ 2.run (SingleThreadEventExecutor.java:101)
java.lang.Thread.run(Thread.java:745)

线程main中的异常javax.jms.JMSRuntimeException:无法创建会话工厂
在org.hornetq.jms.client.JmsExceptionUtils.convertToRuntimeException(JmsExceptionUtils.java:98)
在org.hornetq.jms.client.HornetQConnectionFactory.createContext(HornetQConnectionFactory.java:149)
在org.hornetq.jms.client.HornetQConnectionFactory.createContext(HornetQConnectionFactory.java:130)
在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.in voke(DelegatingMethodMethodAccessorImpl.java:43)
在java.lang.reflect.Method.invoke(Method.java:483)
在com.intellij.rt.execution.application.AppMain.main(AppMain。 java:134)
导致:javax.jms.JMSException:无法在org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:673)中创建会话工厂

org.hornetq.jms.client.HornetQConnectionFactory.createContext(HornetQConnectionFactory.java:140)
... 7更多
导致:HornetQNotConnectedException [errorType = NOT_CONNECTED message = HQ119007:无法连接到服务器。试用所有可用的服务器。]
在org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:905)
在org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory .java:669)
... 8更多


解决方案

我刚刚找到了解决这个问题的办法。我也在通过它。



在您的情况下,问题出在JBoss配置中。在我的情况下,问题出在Wildfly 8.2。



您可能在JBoss中使用以下参数:
jboss.bind.address = 0.0.0.0



我在我的wildfly中使用这个参数让他接受来自任何IP的外部连接,因为我的Wildfly在互联网上暴露。



问题是,如果您没有指定JBoss / Wildfly设置,HornetQ应该向正在进行远程挂起的JMS客户端报告哪个IP,HornetQ会假定IP是在jboss.bind.address中设置的。在这种情况下,0.0.0.0不是有效的IP。您可能在其日志中看到以下消息:JBoss:

情况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解析此名称时,他不能那么会发生以下失败:

解决问题的方法是配置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-connectorsocket-binding =http-remote-jms>
< param key =http-upgrade-endpointvalue =http-acceptor/>
< / http-connector>
< / connectors>
...
< / hornetq-server>
< / subsystem>

AND

 < socket-binding-group name =standard-socketsdefault-interface =publicport-offset =$ {jboss.socket.binding.port-offset:0}> 
...
< outbound-socket-binding name =http-remote-jms>
< remote-destination host =YOUR_REAL_HOSTNAMEport =$ {jboss.http.port:8080}/>
< / outbound-socket-binding>
< / socket-binding-group>

请注意,我没有使用https,因为我无法使用https for JMS进行Wildfly。 / p>

I'm using Docker to link JMS server container to another JMS client container. But when I run the server in the docker container, the client can not connect to the server correctly. I exposed port 443 on docker (Is there any other port which JMS uses?)

I can successfully create destication, but not the JMS context:

String PROVIDER_URL = "https-remoting://MYDOMAIN:443";
...

/** PASSED **/
Destination destination = (Destination) namingContext.lookup(destinationString);

/** HAS ERROR **/
JMSContext context = connectionFactory.createContext(username, password)

Here is the error:

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
解决方案

I just found the solution to this problem. I was also going through it.

In your case the problem is in the JBoss configuration. In my case the problem was in Wildfly 8.2.

You are probably using the following parameter in your JBoss:jboss.bind.address = 0.0.0.0

I am using this parameter in my wildfly for him to accept external connections from any IP because my Wildfly is exposed on the Internet.

The problem is that if you do not specify the JBoss/Wildfly settings which IP that HornetQ should report to the JMS clients that are doing remote loockup HornetQ will assume that the IP is what is set in jboss.bind.address. In this case it will take that 0.0.0.0 is not a valid IP. You probably see the following message in its log JBoss:

In this case HornetQ will use the host defined in the machine name. On linux for example it will use what is defined in /etc/hostname.

There is another problem. Because usually the hostname is not a valid host on the Internet can be resolved to an IP via a DNS service.

Then notice what is probably happening to you: Your JBoss server is scheduled to give bind to 0.0.0.0, your HornetQ (embedded in JBoss) is trying to take this IP and how it is not a valid IP he is taking the hostname of your server. When your remote JMS client (that is outside of your local network) makes a loockup on your JBoss the HornetQ reports to the client that he must seek the HornetQ resources on the host YOUR_HOSTNAME_LOCAL_SERVER but when it tries to resolve this name through DNS he can not then the following failure occurs:

The solution to the problem is to configure the JBoss which host it should inform for customers who are doing loockup remote.

In my case the setting for the wildfly is as follows. The standalone.xml file must be changed:

<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>

AND

<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>

Note that I'm not using https because I could not do Wildfly work with https for JMS.

这篇关于使用HornetQ(JBoss)在Docker容器上公开的JMS所需的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 20:02