我有一个应该从中读取的spring-boot应用程序(1.5.14) 旧版JBoss EAP 6.4提供的HornetQ JMS主题
我知道从1.4.8春季开始就不再支持HornetQ。 但是目前尚无可能替换该旧系统。
我在gradle中的依赖项:
compile("org.springframework.boot:spring-boot-starter-hornetq:1.4.7.RELEASE")
这是我的TopicListener类:
@Component
public class LegacyTopicListener {
@JmsListener(destination = "jms/topic/legacyTopic", containerFactory = "myFactory")
public void onReceive(String content) {
System.out.println(content);
}
}
这是我的JmsConfiguration类:
@Configuration
@EnableJms
class JmsConfiguration {
@Bean
public DefaultJmsListenerContainerFactory myFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
try {
factory.setConnectionFactory(connectionFactory());
} catch (Exception e) {
e.printStackTrace();
}
return factory;
}
@Bean
public ConnectionFactory connectionFactory() throws Exception {
HornetQConnectionFactory connectionFactory = new HornetQConnectionFactory(false,
transportConfiguration());
UserCredentialsConnectionFactoryAdapter adapter
= new UserCredentialsConnectionFactoryAdapter();
adapter.setUsername("daUser");
adapter.setPassword("daPassword");
adapter.setTargetConnectionFactory(connectionFactory);
return adapter;
}
private TransportConfiguration transportConfiguration() throws Exception {
Map<String, Object> map = new HashMap<>();
String host = InetAddress.getLocalHost().getHostAddress();
map.put("host", host);
map.put("port", "5647");
TransportConfiguration configuration = new TransportConfiguration(
"org.hornetq.core.remoting.impl.netty.NettyConnectorFactory", map);
return configuration;
}
}
当我尝试连接JMS主题时,我遇到了以下异常:
2019-01-29 17:14:09,975 [ads-1571167970)] ERROR o.h.c.client - HQ214013: Failed to decode packet
java.lang.IllegalArgumentException: HQ119032: Invalid type: 0
at org.hornetq.core.protocol.core.impl.PacketDecoder.decode(PacketDecoder.java:447) ~[hornetq-core-client-2.4.7.Final.jar:na]
at org.hornetq.core.protocol.ClientPacketDecoder.decode(ClientPacketDecoder.java:56) ~[hornetq-core-client-2.4.7.Final.jar:na]
at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.bufferReceived(RemotingConnectionImpl.java:493) ~[hornetq-core-client-2.4.7.Final.jar:na]
at org.hornetq.core.client.impl.ClientSessionFactoryImpl$DelegatingBufferHandler.bufferReceived(ClientSessionFactoryImpl.java:1712) ~[hornetq-core-client-2.4.7.Final.jar:na]
at org.hornetq.core.remoting.impl.netty.HornetQChannelHandler.channelRead(HornetQChannelHandler.java:73) ~[hornetq-core-client-2.4.7.Final.jar:na]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) ~[netty-all-4.0.13.Final.jar:4.0.13.Final]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) ~[netty-all-4.0.13.Final.jar:4.0.13.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:153) [netty-all-4.0.13.Final.jar:4.0.13.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338) ~[netty-all-4.0.13.Final.jar:4.0.13.Final]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324) ~[netty-all-4.0.13.Final.jar:4.0.13.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [netty-all-4.0.13.Final.jar:4.0.13.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:122) [netty-all-4.0.13.Final.jar:4.0.13.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:485) [netty-all-4.0.13.Final.jar:4.0.13.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452) [netty-all-4.0.13.Final.jar:4.0.13.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346) [netty-all-4.0.13.Final.jar:4.0.13.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101) [netty-all-4.0.13.Final.jar:4.0.13.Final]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]
在春季引导之后,尝试继续并引发此异常
2019-01-29 17:14:40,009 [ main] INFO o.a.c.h.Http11NioProtocol - Starting ProtocolHandler ["http-nio-10480"]
2019-01-29 17:14:40,012 [ main] INFO o.a.t.u.n.NioSelectorPool - Using a shared selector for servlet write/read
2019-01-29 17:14:40,025 [ main] INFO TomcatEmbeddedServletContainer - Tomcat started on port(s): 10480 (http)
2019-01-29 17:14:40,032 [ main] INFO .s.StatsApplication - Started StatsApplication in 38.181 seconds (JVM running for 38.711)
2019-01-29 17:14:40,423 [on(4)-127.0.0.1] WARN o.s.b.a.h.JmsHealthIndicator - Health check failed
2019-01-29 17:14:40,423 [on(4)-127.0.0.1] WARN o.s.b.a.h.JmsHealthIndicator - Health check failed
javax.jms.JMSException: Failed to create session factory
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:673) ~[hornetq-jms-client-2.4.7.Final.jar:na]
at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:112) ~[hornetq-jms-client-2.4.7.Final.jar:na]
at org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter.doCreateConnection(UserCredentialsConnectionFactoryAdapter.java:178) ~[spring-jms-4.3.18.RELEASE.jar:4.3.18.RELEASE]
at org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter.createConnection(UserCredentialsConnectionFactoryAdapter.java:152) ~[spring-jms-4.3.18.RELEASE.jar:4.3.18.RELEASE]
at org.springframework.boot.actuate.health.JmsHealthIndicator.doHealthCheck(JmsHealthIndicator.java:38) ~[spring-boot-actuator-1.5.14.RELEASE.jar:1.5.14.RELEASE]
at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:43) ~[spring-boot-actuator-1.5.14.RELEASE.jar:1.5.14.RELEASE]
at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:68) [spring-boot-actuator-1.5.14.RELEASE.jar:1.5.14.RELEASE]
at org.springframework.boot.actuate.endpoint.HealthEndpoint.invoke(HealthEndpoint.java:86) [spring-boot-actuator-1.5.14.RELEASE.jar:1.5.14.RELEASE]
at org.springframework.boot.actuate.endpoint.HealthEndpoint.invoke(HealthEndpoint.java:36) [spring-boot-actuator-1.5.14.RELEASE.jar:1.5.14.RELEASE]
at org.springframework.boot.actuate.endpoint.jmx.DataEndpointMBean.getData(DataEndpointMBean.java:46) [spring-boot-actuator-1.5.14.RELEASE.jar:1.5.14.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) [na:1.8.0_144]
at sun.reflect.GeneratedMethodAccessor351.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) [na:1.8.0_144]
at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1252) [na:1.8.0_144]
at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_144]
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) [na:1.8.0_144]
at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1246) [na:1.8.0_144]
at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:1085) [na:1.8.0_144]
at org.springframework.jmx.export.SpringModelMBean.invoke(SpringModelMBean.java:90) [spring-context-4.3.18.RELEASE.jar:4.3.18.RELEASE]
at javax.management.modelmbean.RequiredModelMBean.getAttribute(RequiredModelMBean.java:1562) [na:1.8.0_144]
at org.springframework.jmx.export.SpringModelMBean.getAttribute(SpringModelMBean.java:109) [spring-context-4.3.18.RELEASE.jar:4.3.18.RELEASE]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:647) [na:1.8.0_144]
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:678) [na:1.8.0_144]
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1445) [na:1.8.0_144]
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) [na:1.8.0_144]
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) [na:1.8.0_144]
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) [na:1.8.0_144]
at javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:639) [na:1.8.0_144]
at sun.reflect.GeneratedMethodAccessor337.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) [na:1.8.0_144]
at sun.rmi.transport.Transport$1.run(Transport.java:200) [na:1.8.0_144]
at sun.rmi.transport.Transport$1.run(Transport.java:197) [na:1.8.0_144]
at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_144]
at sun.rmi.transport.Transport.serviceCall(Transport.java:196) [na:1.8.0_144]
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) [na:1.8.0_144]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) [na:1.8.0_144]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) [na:1.8.0_144]
at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_144]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) [na:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_144]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_144]
Caused by: java.lang.NullPointerException: null
at org.hornetq.core.client.impl.ClientSessionFactoryImpl$PingRunnable.send(ClientSessionFactoryImpl.java:1823) ~[hornetq-core-client-2.4.7.Final.jar:na]
at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnection(ClientSessionFactoryImpl.java:1423) ~[hornetq-core-client-2.4.7.Final.jar:na]
at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnectionWithRetry(ClientSessionFactoryImpl.java:1121) ~[hornetq-core-client-2.4.7.Final.jar:na]
at org.hornetq.core.client.impl.ClientSessionFactoryImpl.connect(ClientSessionFactoryImpl.java:266) ~[hornetq-core-client-2.4.7.Final.jar:na]
at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:881) ~[hornetq-core-client-2.4.7.Final.jar:na]
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:669) ~[hornetq-jms-client-2.4.7.Final.jar:na]
有人可以帮忙吗?谢谢。
通过cli配置EAP系统:
/subsystem=messaging/hornetq-server=default/jms-topic=legacyTopic:add(entries=["jms/topic/legacyTopic", "java:jboss/exported/jms/topic/legacyTopic"])
JBoss套接字绑定:(端口偏移为1200)
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
<socket-binding name="management-native" interface="management" port="${jboss.management.native.port:9999}"/>
<socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
<socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9443}"/>
<socket-binding name="ajp" port="8009"/>
<socket-binding name="http" port="8080"/>
<socket-binding name="https" port="8443"/>
<socket-binding name="jacorb" interface="unsecure" port="3528"/>
<socket-binding name="jacorb-ssl" interface="unsecure" port="3529"/>
<socket-binding name="messaging" port="5445"/>
<socket-binding name="messaging-group" port="0" multicast-address="${jboss.messaging.group.address:231.7.7.7}" multicast-port="${jboss.messaging.group.port:9876}"/>
<socket-binding name="messaging-throughput" port="5455"/>
<socket-binding name="remoting" port="4447"/>
<socket-binding name="txn-recovery-environment" port="4712"/>
<socket-binding name="txn-status-manager" port="4713"/>
<socket-binding name="jgroups-tcp" port="7600"/>
<socket-binding name="jgroups-tcp-fd" port="57600"/>
</socket-binding-group>
使用端口6645后出现错误:
Caused by: org.hornetq.api.core.HornetQConnectionTimedOutException: HQ119013: Timed out waiting to receive cluster topology. Group:null
at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:946) ~[hornetq-core-client-2.4.7.Final.jar:na]
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:669) ~[hornetq-jms-client-2.4.7.Final.jar:na]
... 49 common frames omitted
答案 0 :(得分:0)
我找到了解决我问题的方法。但这是一个肮脏的解决方案。
JBoss EAP 6.4.x使用HornetQ 2.3.x版本。春季启动应用 使用2.4.x,这是HornetQ的较新版本,与JBoss EAP 6.4.x内置的版本相比。
存在版本兼容性问题,该问题不允许HornetQ 2.3.x和2.4.x的互操作性,因此会导致错误。
要解决我的问题,我必须确保我的所有代码(客户端和服务器端)都使用相同的库。
所以我必须更改gradle依赖项:
compile('org.springframework.boot:spring-boot-starter-hornetq:1.4.7.RELEASE') {
exclude group: "org.hornetq"
}
compile("org.hornetq:hornetq-core-client:2.3.25.SP8-redhat-1")
compile("org.hornetq:hornetq-jms-client:2.3.25.SP8-redhat-1")
之后,spring-boot应用程序可以与JBoss HornetQ Topic对话