由于javax.jms.JMSException,应用程序间歇性地无法在ActiceMQ“Classic”上发送消息:无法连接到代理URL

Intermittently application is not able to send message on ActiceMQ "Classic" due to javax.jms.JMSException: Could not connect to broker URL

提问人:Prabhjot Sokhi 提问时间:9/26/2023 最后编辑:Prabhjot Sokhi 更新时间:9/27/2023 访问量:48

问:

应用程序使用池化 JMS 连接。在启动时,应用程序工作正常,但几天后它无法向 ActiveMQ“Classic”发送消息。应用程序重新启动后,它会再次连接并在接下来的几天内正常工作。

以下是错误消息: 初始错误是:

2023-09-18 00:03:15,051 ERROR c.n.v.r.i.l.BulkMessageStorageQueueListener [pool-7-thread-1] Exception in sending messages, rollbacking messages with size: 78
org.springframework.jms.IllegalStateException: com.thoughtworks.xstream.InitializationException: Could not instantiate mapper : com.thoughtworks.xstream.mapper.EnumMapper; nested exception is javax.jms.IllegalStateException: com.thoughtworks.xstream.InitializationException: Could not instantiate mapper : com.thoughtworks.xstream.mapper.EnumMapper
    at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:274) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:185) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:507) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:584) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:691) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at com.project.xxx.BulkMessageSender.sendStatusMessage(BulkMessageSender.java:71) ~[classes/:04.17.02.35]
    at com.project.xxx.BulkMessageStorageQueueListener.lambda$setupConsumer$0(BulkMessageStorageQueueListener.java:113) ~[classes/:04.17.02.35]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:?]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) ~[?:1.8.0_222]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) ~[?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_222]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:?]
    at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_222]
Caused by: javax.jms.IllegalStateException: com.thoughtworks.xstream.InitializationException: Could not instantiate mapper : com.thoughtworks.xstream.mapper.EnumMapper
    at org.apache.activemq.jms.pool.ConnectionPool.createSession(ConnectionPool.java:162) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnection.createSession(PooledConnection.java:167) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.springframework.jms.support.JmsAccessor.createSession(JmsAccessor.java:208) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:495) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    ... 11 more
Caused by: com.thoughtworks.xstream.InitializationException: Could not instantiate mapper : com.thoughtworks.xstream.mapper.EnumMapper
    at com.thoughtworks.xstream.XStream.buildMapperDynamically(XStream.java:646) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.buildMapper(XStream.java:616) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:587) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:515) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:484) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:430) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:369) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at org.apache.activemq.transport.stomp.XStreamSupport.createXStream(XStreamSupport.java:31) ~[activemq-stomp-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.xstream.XStreamWireFormat.createXStream(XStreamWireFormat.java:127) ~[activemq-http-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.xstream.XStreamWireFormat.getXStream(XStreamWireFormat.java:113) ~[activemq-http-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.xstream.XStreamWireFormat.marshalText(XStreamWireFormat.java:89) ~[activemq-http-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.http.HttpClientTransport.oneway(HttpClientTransport.java:106) ~[activemq-http-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.MutexTransport.oneway(MutexTransport.java:68) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.ResponseCorrelator.asyncRequest(ResponseCorrelator.java:81) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.ResponseCorrelator.request(ResponseCorrelator.java:86) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1392) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1486) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnection.createSession(ActiveMQConnection.java:329) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.ConnectionPool.makeSession(ConnectionPool.java:112) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.ConnectionPool$1.makeObject(ConnectionPool.java:82) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.ConnectionPool$1.makeObject(ConnectionPool.java:78) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.create(GenericKeyedObjectPool.java:1041) ~[commons-pool2-2.7.0.jar:2.7.0]
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:342) ~[commons-pool2-2.7.0.jar:2.7.0]
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:265) ~[commons-pool2-2.7.0.jar:2.7.0]
    at org.apache.activemq.jms.pool.ConnectionPool.createSession(ConnectionPool.java:144) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnection.createSession(PooledConnection.java:167) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.springframework.jms.support.JmsAccessor.createSession(JmsAccessor.java:208) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:495) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    ... 11 more
Caused by: java.lang.ClassNotFoundException: com.thoughtworks.xstream.mapper.EnumMapper
    at com.thoughtworks.xstream.core.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:148) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at java.lang.Class.forName0(Native Method) ~[?:1.8.0_222]
    at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_222]
    at com.thoughtworks.xstream.XStream.buildMapperDynamically(XStream.java:642) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.buildMapper(XStream.java:616) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:587) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:515) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:484) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:430) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:369) ~[xstream-1.4.11.1.jar:1.4.11.1]
    at org.apache.activemq.transport.stomp.XStreamSupport.createXStream(XStreamSupport.java:31) ~[activemq-stomp-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.xstream.XStreamWireFormat.createXStream(XStreamWireFormat.java:127) ~[activemq-http-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.xstream.XStreamWireFormat.getXStream(XStreamWireFormat.java:113) ~[activemq-http-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.xstream.XStreamWireFormat.marshalText(XStreamWireFormat.java:89) ~[activemq-http-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.http.HttpClientTransport.oneway(HttpClientTransport.java:106) ~[activemq-http-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.MutexTransport.oneway(MutexTransport.java:68) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.ResponseCorrelator.asyncRequest(ResponseCorrelator.java:81) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.ResponseCorrelator.request(ResponseCorrelator.java:86) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1392) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1486) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnection.createSession(ActiveMQConnection.java:329) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.ConnectionPool.makeSession(ConnectionPool.java:112) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.ConnectionPool$1.makeObject(ConnectionPool.java:82) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.ConnectionPool$1.makeObject(ConnectionPool.java:78) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.create(GenericKeyedObjectPool.java:1041) ~[commons-pool2-2.7.0.jar:2.7.0]
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:342) ~[commons-pool2-2.7.0.jar:2.7.0]
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:265) ~[commons-pool2-2.7.0.jar:2.7.0]
    at org.apache.activemq.jms.pool.ConnectionPool.createSession(ConnectionPool.java:144) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnection.createSession(PooledConnection.java:167) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.springframework.jms.support.JmsAccessor.createSession(JmsAccessor.java:208) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:495) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    ... 11 more

以下错误持续出现,直到应用程序未重新启动。

2023-09-18 00:03:16,363 ERROR c.n.v.r.i.l.BulkMessageStorageQueueListener [pool-7-thread-1] Exception in sending messages, rollbacking messages with size: 94
org.springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JMS processing; nested exception is javax.jms.JMSException: Error while attempting to add new Connection to the pool; nested exception is javax.jms.JMSException: Could not connect to broker URL: https://hostName:443/destination-name?useInactivityMonitor=false. Reason: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org/apache/http/client/version.properties]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:311) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:185) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:507) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:584) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:691) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at com.project.xxx.BulkMessageSender.sendStatusMessage(BulkMessageSender.java:71) ~[classes/:04.17.02.35]
    at com.project.xxx.BulkMessageStorageQueueListener.lambda$setupConsumer$0(BulkMessageStorageQueueListener.java:113) ~[classes/:04.17.02.35]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:?]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) ~[?:1.8.0_222]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) ~[?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_222]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:?]
    at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_222]
Caused by: javax.jms.JMSException: Error while attempting to add new Connection to the pool
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createJmsException(PooledConnectionFactory.java:279) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:230) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:209) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:196) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    ... 11 more
Caused by: javax.jms.JMSException: Could not connect to broker URL: https://hostName:443/destination-name?useInactivityMonitor=false. Reason: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org/apache/http/client/version.properties]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:374) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:304) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:244) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:288) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:97) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:94) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.create(GenericKeyedObjectPool.java:1041) ~[commons-pool2-2.7.0.jar:2.7.0]
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.addObject(GenericKeyedObjectPool.java:1238) ~[commons-pool2-2.7.0.jar:2.7.0]
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:226) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:209) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:196) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    ... 11 more
Caused by: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org/apache/http/client/version.properties]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1427) ~[?:?]
    at org.apache.catalina.loader.WebappClassLoaderBase.getResourceAsStream(WebappClassLoaderBase.java:1135) ~[?:?]
    at org.apache.http.util.VersionInfo.loadVersionInfo(VersionInfo.java:233) ~[httpcore-4.4.13.jar:4.4.13]
    at org.apache.http.util.VersionInfo.getUserAgent(VersionInfo.java:319) ~[httpcore-4.4.13.jar:4.4.13]
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:1057) ~[httpclient-4.5.12.jar:4.5.12]
    at org.apache.activemq.transport.http.HttpClientTransport.createHttpClient(HttpClientTransport.java:347) ~[activemq-http-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.http.HttpClientTransport.getReceiveHttpClient(HttpClientTransport.java:233) ~[activemq-http-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.http.HttpClientTransport.doStart(HttpClientTransport.java:250) ~[activemq-http-5.15.12.jar:5.15.12]
    at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:55) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:64) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:64) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:354) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:304) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:244) ~[activemq-client-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:288) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:97) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:94) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.create(GenericKeyedObjectPool.java:1041) ~[commons-pool2-2.7.0.jar:2.7.0]
    at org.apache.commons.pool2.impl.GenericKeyedObjectPool.addObject(GenericKeyedObjectPool.java:1238) ~[commons-pool2-2.7.0.jar:2.7.0]
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:226) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:209) ~[activemq-jms-pool-5.15.12.jar:5.15.12]
    at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:196) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494) ~[spring-jms-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    ... 11 more

下面是用于配置客户端应用程序的代码:

public class ActiveMQConfig {

    private static final Logger logger = LoggerFactory.getLogger(ActiveMQConfig.class);

    // Active Mq properties

    @Value("${activeMQ.broker.url}")
    private String brokerUrl;

    @Value("${jms.listener.concurrency}")
    private String concurrency;
    
    // The duration between attempts to redliver a message
    @Value("${jms.rollback.redelivery.delay:10000}")
    private int redeliveryDelay;

    // Maximum number of times a redlivery of a message will be attempted -1 is infinite
    @Value("${jms.rollback.maximum.redeliveries:-1}")
    private String maximumRedelivery;

    @Value("${message.activeMQ.pool.max.connections:10}")
    private int activeMqPoolMaxConnections;

    @Bean
    public JmsListenerContainerFactory jmsListenerContainerFactory(
            @Qualifier("jmsConnectionFactoryActiveMQ") ConnectionFactory connectionFactory,
            DefaultJmsListenerContainerFactoryConfigurer configurer) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConcurrency(concurrency);
        factory.setSessionTransacted(true);
        factory.setAutoStartup(false);
        factory.setErrorHandler(errorHandler -> logger.error("An error has occurred in the transaction: {}",
                errorHandler.getMessage()));
        configurer.configure(factory, connectionFactory);
        return factory;
    }

    @Bean
    @Primary
    public ActiveMQConnectionFactory jmsConnectionFactoryActiveMQ() {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        connectionFactory.setTrustAllPackages(true);
        
        // create re-delivery policy to configure re-attempt count and delay
        // when message is rolled back on queue in case of any exception
        RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
        redeliveryPolicy.setMaximumRedeliveries(Integer.parseInt(maximumRedelivery));
        redeliveryPolicy.setRedeliveryDelay(redeliveryDelay);
        
        connectionFactory.setRedeliveryPolicy(redeliveryPolicy);
        connectionFactory.setBrokerURL(brokerUrl);

        return connectionFactory;
    }

    @Bean
    public JmsTemplate jmsTemplateActiveMQ(PooledConnectionFactory pooledConnectionFactory) {
        JmsTemplate jmsTemplate = new JmsTemplate();
        jmsTemplate.setPubSubDomain(false);
        jmsTemplate.setConnectionFactory(pooledConnectionFactory);
        return jmsTemplate;
    }

    @Bean
    public PooledConnectionFactory pooledConnectionFactory(ActiveMQConnectionFactory connectionFactory) {
        PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory();
        pooledConnectionFactory.setConnectionFactory(connectionFactory);
        pooledConnectionFactory.setMaxConnections(activeMqPoolMaxConnections);
        return pooledConnectionFactory;

    }

}

注意:

  • activeMqPoolMaxConnections 为 10。
  • 消息流入量不太高。这就像 400-500 条消息。
  • 我们还用于对消息进行分组(JMSXGroupIDmessage.setStringProperty("JMSXGroupID", groupId);)
  • ActiveMQ 连接 url 为activeMQ.broker.url=https://dummy.dns.name.com/destination-name?useInactivityMonitor=false
Java ActiveMQ spring-JMS

评论

0赞 Justin Bertram 9/27/2023
根据堆栈跟踪,您似乎正在使用 HTTP 传输。这是对的吗?如果是这样,您使用它是否有特殊原因?你能用普通的TCP传输来代替吗?看起来你对 HTTP 传输的使用与你遇到的问题直接相关。
0赞 Tim Bish 9/27/2023
发布您正在使用的连接 URI 通常是一个有用的补充。
0赞 Prabhjot Sokhi 9/27/2023
@JustinBertram我们有 2 个独立的应用程序,并且中间有一个防火墙,出于安全原因,我们必须使用 HTTPS。
0赞 Prabhjot Sokhi 9/27/2023
@TimBish连接 URI 如下所示 activeMQ.brokerurl=dummy.dns.name.com:443/...
0赞 Justin Bertram 9/27/2023
这看起来像是 HTTP 传输中的一个错误,因此如果您别无选择只能使用它,那么我建议您尝试升级,因为 ActiveMQ 5.15.12 现在已经超过 3 年了。也就是说,HTTP 传输不常用,因此升级可能无法解决问题。您还可以考虑迁移到 ActiveMQ Artemis(即 ActiveMQ 的下一代代理),它也支持 HTTP

答: 暂无答案