我正在一个办公项目中,我们需要实现Apache ActiveMQ Artemis进行消息传递。当我尝试使用一个独立的Java项目(通过从生产者发送消息)连接代理时,它可以工作,但是部署在 Tomcat 上的相同代码会产生奇怪的异常(Tomcat 9.0.20)。
NodeUp ServerLocatorImpl [initialConnectors=TransportConfiguration(name=238d338c-8ce0-11e9-a992-023df9f858ac, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61616&host=52-66-244-62], discoveryGroupConfiguration=null]::nodeID=32032cfb-8092-11e9-8980-0a59e49d9556, connectorPair=Pair[a=TransportConfiguration(name=netty-connector, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61616&host=172-31-6-127, b=TransportConfiguration(name=netty-connector, factory=org-apache-activemq-artemis-core-remoting-impl-netty-NettyConnectorFactory) ?port=61617&host=172-31-15-231]
java.lang.Exception: trace
at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.notifyNodeUp(ServerLocatorImpl.java:1467) [artemis-jms-client-all-2.8.1.jar:2.8.1]
at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl$SessionFactoryTopologyHandler.notifyNodeUp(ClientSessionFactoryImpl.java:1384) [artemis-jms-client-all-2.8.1.jar:2.8.1]
at org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQClientProtocolManager$Channel0Handler.notifyTopologyChange(ActiveMQClientProtocolManager.java:516) [artemis-jms-client-all-2.8.1.jar:2.8.1]
at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:427) [artemis-jms-client-all-2.8.1.jar:2.8.1]
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:328) [artemis-jms-client-all-2.8.1.jar:2.8.1]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905) [artemis-jms-client-all-2.8.1.jar:2.8.1]
at org.apache.activemq.artemis.utils.ActiveMQThreadFactory$1.run(ActiveMQThreadFactory.java:118) [artemis-jms-client-all-2.8.1.jar:2.8.1]
12/Jun/2019 12:33:11,357 Topology@2b7b2751::NewMemberAdd nodeId=32032cfb-8092-11e9-8980-0a59e49d9556 member = TopologyMember[id = 32032cfb-8092-11
12/Jun/2019 12:33:11,376 Reading string with utfSize=50
12/Jun/2019 12:33:11,397 RemotingConnectionID=be5d8dfa handling packet PACKET(ActiveMQExceptionMessage_V2)[type=20, channelID=1, responseAsync=true, requiresResponse=false, correlationID=0, packetObject=ActiveMQExceptionMessage_V2, exception= ActiveMQIncompatibleClientServerException[errorType=INCOMPATIBLE_CLIENT_SERVER_VERSIONS message=AMQ119033: Server and client versions incompatible]]
12/Jun/2019 12:33:11,398 Saving string with utfSize=36 stringSize=36
12/Jun/2019 12:33:11,398 RemotingConnectionID=be5d8dfa Sending blocking PACKET(CreateSessionMessage)[type=30, channelID=1, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=CreateSessionMessage, autoCommitAcks=false, autoCommitSends=false, defaultAddress=null, minLargeMessageSize=102400, name=23dba1af-8ce0-11e9-a992-023df9f858ac, password=****, preAcknowledge=false, sessionChannelID=11, username=testuser, version=129, windowSize=-1, xa=false]
12/Jun/2019 12:33:11,420 RemotingConnectionID=be5d8dfa handling packet PACKET(CreateSessionResponseMessage)[type=31, channelID=1, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=CreateSessionResponseMessage, serverVersion=129]
12/Jun/2019 12:33:11,429 RemotingConnectionID=be5d8dfa Setting handler on Channel[id=11, RemotingConnectionID=be5d8dfa, handler=null] as org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQSessionContext$ClientSessionPacketHandler@1b0192b2
12/Jun/2019 12:33:11,436 Saving string with utfSize=11 stringSize=11
12/Jun/2019 12:33:11,436 RemotingConnectionID=be5d8dfa Sending blocking PACKET(SessionAddMetaDataMessageV2)[type=105, channelID=11, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=SessionAddMetaDataMessageV2, key=jms-session, data=, requiresConfirmation=true]
12/Jun/2019 12:33:11,439 RemotingConnectionID=be5d8dfa handling packet PACKET(NullResponseMessage)[type=21, channelID=11, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=NullResponseMessage]
12/Jun/2019 12:33:11,441 Saving string with utfSize=36 stringSize=36
12/Jun/2019 12:33:11,441 RemotingConnectionID=be5d8dfa Sending blocking PACKET(CreateSessionMessage)[type=30, channelID=1, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=CreateSessionMessage, autoCommitAcks=true, autoCommitSends=true, defaultAddress=null, minLargeMessageSize=102400, name=23e6ec50-8ce0-11e9-a992-023df9f858ac, password=****, preAcknowledge=false, sessionChannelID=12, username=testuser, version=130, windowSize=-1, xa=false]
12/Jun/2019 12:33:11,443 Reading string with utfSize=50
12/Jun/2019 12:33:11,443 RemotingConnectionID=be5d8dfa handling packet PACKET(ActiveMQExceptionMessage)[type=20, channelID=1, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=ActiveMQExceptionMessage, exception= ActiveMQIncompatibleClientServerException[errorType=INCOMPATIBLE_CLIENT_SERVER_VERSIONS message=AMQ119033: Server and client versions incompatible]]
12/Jun/2019 12:33:11,444 Saving string with utfSize=36 stringSize=36
12/Jun/2019 12:33:11,444 RemotingConnectionID=be5d8dfa Sending blocking PACKET(CreateSessionMessage)[type=30, channelID=1, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=CreateSessionMessage, autoCommitAcks=true, autoCommitSends=true, defaultAddress=null, minLargeMessageSize=102400, name=23e6ec50-8ce0-11e9-a992-023df9f858ac, password=****, preAcknowledge=false, sessionChannelID=13, username=testuser, version=129, windowSize=-1, xa=false]
12/Jun/2019 12:33:11,445 RemotingConnectionID=be5d8dfa handling packet PACKET(CreateSessionResponseMessage)[type=31, channelID=1, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=CreateSessionResponseMessage, serverVersion=129]
12/Jun/2019 12:33:11,445 RemotingConnectionID=be5d8dfa Setting handler on Channel[id=13, RemotingConnectionID=be5d8dfa, handler=null] as org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQSessionContext$ClientSessionPacketHandler@2c7f11d8
12/Jun/2019 12:33:11,460 Saving string with utfSize=11 stringSize=11
12/Jun/2019 12:33:11,460 RemotingConnectionID=be5d8dfa Sending blocking PACKET(SessionAddMetaDataMessageV2)[type=105, channelID=13, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=SessionAddMetaDataMessageV2, key=jms-session, data=, requiresConfirmation=true]
12/Jun/2019 12:33:11,462 RemotingConnectionID=be5d8dfa handling packet PACKET(NullResponseMessage)[type=21, channelID=13, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=NullResponseMessage]
12/Jun/2019 12:33:11,462 RemotingConnectionID=be5d8dfa Sending packet nonblocking PACKET(PacketImpl)[type=67, channelID=13, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=PacketImpl] on channelID=13
12/Jun/2019 12:33:11,462 RemotingConnectionID=be5d8dfa Writing buffer for channelID=13
12/Jun/2019 12:33:11,466 Calling close on session ClientSessionImpl [name=23e6ec50-8ce0-11e9-a992-023df9f858ac, username=testuser, closed=false, factory = org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl@1f7c2374, metaData=(jms-session=,)]@77061669
12/Jun/2019 12:33:11,467 RemotingConnectionID=be5d8dfa Sending blocking PACKET(SessionCloseMessage)[type=69, channelID=13, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=SessionCloseMessage]
12/Jun/2019 12:33:11,470 RemotingConnectionID=be5d8dfa handling packet PACKET(NullResponseMessage)[type=21, channelID=13, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=NullResponseMessage]
12/Jun/2019 12:33:11,471 calling cleanup on ClientSessionImpl [name=23e6ec50-8ce0-11e9-a992-023df9f858ac, username=testuser, closed=false, factory = org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl@1f7c2374, metaData=(jms-session=,)]@77061669
12/Jun/2019 12:33:11,476 Calling close on session ClientSessionImpl [name=23dba1af-8ce0-11e9-a992-023df9f858ac, username=testuser, closed=false, factory = org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl@1f7c2374, metaData=(jms-session=,)]@33a18279
12/Jun/2019 12:33:11,476 RemotingConnectionID=be5d8dfa Sending blocking PACKET(SessionCloseMessage)[type=69, channelID=11, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=SessionCloseMessage]
12/Jun/2019 12:33:11,478 RemotingConnectionID=be5d8dfa handling packet PACKET(NullResponseMessage)[type=21, channelID=11, responseAsync=false, requiresResponse=false, correlationID=-1, packetObject=NullResponseMessage]
12/Jun/2019 12:33:11,478 calling cleanup on ClientSessionImpl [name=23dba1af-8ce0-11e9-a992-023df9f858ac, username=testuser, closed=false, factory = org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl@1f7c2374, metaData=(jms-session=,)]@33a18279
12/Jun/2019 12:33:11,482 AMQ214026: Failure captured on connectionID=be5d8dfa, performing failover or reconnection now
org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException: AMQ219006: Channel disconnected
at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.connectionDestroyed(ClientSessionFactoryImpl.java:356) ~[artemis-jms-client-all-2.8.1.jar:2.8.1]
at org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector$Listener$1.run(NettyConnector.java:1134) ~[artemis-jms-client-all-2.8.1.jar:2.8.1]
at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:42) ~[artemis-jms-client-all-2.8.1.jar:2.8.1]
at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:31) ~[artemis-jms-client-all-2.8.1.jar:2.8.1]
at org.apache.activemq.artemis.utils.actors.ProcessorBase.executePendingTasks(ProcessorBase.java:66) ~[artemis-jms-client-all-2.8.1.jar:2.8.1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_181]
at org.apache.activemq.artemis.utils.ActiveMQThreadFactory$1.run(ActiveMQThreadFactory.java:118) [artemis-jms-client-all-2.8.1.jar:2.8.1]
初始化上下文时,我正在尝试连接到代理。
我得到频道已断开连接,当代理运行时,我使用生产者和使用者运行独立代码,并且代码正常运行。
有时,也会收到客户端和服务器版本不兼容的异常,如您在上面的错误日志中所见。
确切的例外是什么?对于导致连接失败的异常,我真的一无所知。
编辑:-上下文初始化代码
public class IamContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent paramServletContextEvent) {
logger.log(Level.INFO, "Servlet Context Initializer Called.");
String brokerUrl = Config.getInstance().getProperty(Constants.BROKER_URL);
String username = Config.getInstance().getProperty(Constants.QUEUE_USERNAME);
String password = Config.getInstance().getProperty(Constants.QUEUE_PASSWORD);
QueueMessagePollScheduler.getInstance().initializeService();
}
创建会话代码
TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName());
// Create a ConnectionFactory
// this.connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF,transportConfiguration);
// new ActiveMQConnectionFactory(brokerUrl);
this.connectionFactory = ActiveMQJMSClient.createConnectionFactory(brokerUrl, UUIDGenerator.getInstance().generateStringUUID());
// Create a Connection
this.connection = this.connectionFactory.createConnection(username, password);
// Create a Session
this.session = this.connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
this.connection.start();
// Create a MessageProducer from the Session to the Topic or Queue
this.producer = session.createProducer(null);
this.producer.setDeliveryMode(DeliveryMode.PERSISTENT);
}
catch (Exception e) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, e.getMessage(), e);
throw new ActiveMQConectionException(e.getMessage());
}
生产者代码:-
Destination destination = session.createQueue(queueName);
TextMessage message = session.createTextMessage(messageBodyJSON);
producer.send(destination, message);
实际上,相同的代码也适用于Apache Active MQ,但是我的公司希望升级到Apache Active Artemis。