0

我正在使用 spring boot 连接到慰藉队列。我使用下面的教程连接到 solace JMS 队列。 https://www.devglan.com/spring-boot/spring-jms-solace-example 它能够连接到慰藉队列。当应用程序启动并且与 solace queue 的连接工作正常时,我们遇到了一个问题,但是在 solace queue 关闭一段时间后,spring boot 应用程序应该重新连接到 solace queue,而不是重新启动应用程序进行连接。要重新连接安慰队列,我添加了

 connectionFactory.setReconnectRetries(-1);
 connectionFactory.setReconnectRetryWaitInMillis(3000);
 connectionFactory.setConnectRetries(-1);
 connectionFactory.setConnectRetriesPerHost(5);
     

所以代码如下所示

   @Bean
    public SolConnectionFactory solConnectionFactory() throws Exception {
        SolConnectionFactory connectionFactory = SolJmsUtility.createConnectionFactory();
        connectionFactory.setHost(environment.getProperty("solace.java.host"));
        connectionFactory.setVPN(environment.getProperty("solace.java.msgVpn"));
        connectionFactory.setUsername(environment.getProperty("solace.java.clientUsername"));
        connectionFactory.setPassword(environment.getProperty("solace.java.clientPassword"));
        connectionFactory.setClientID(environment.getProperty("solace.java.clientName"));
         connectionFactory.setReconnectRetries(-1);
         connectionFactory.setReconnectRetryWaitInMillis(3000);
         connectionFactory.setConnectRetries(-1);
         connectionFactory.setConnectRetriesPerHost(5);
         
        return connectionFactory;
    }



 @Bean
    public JmsMessageListener jmsMessageListener() {
        return new JmsMessageListener();
    }

    @Bean(destroyMethod = "close")
    public Connection connection() {
        Connection connection = null;
        javax.jms.Session session;
        try {
            connection = solConnectionFactory().createConnection();
            session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
            Queue queue = session.createQueue(environment.getProperty("solace.message.consumer.queue"));
            MessageConsumer messageConsumer = session.createConsumer(queue);
            messageConsumer.setMessageListener(jmsMessageListener());
            connection.setExceptionListener(exceptionListener);
            connection.start();
            logger.info("Connected. Awaiting message...");
        } catch (Exception e) {
            logger.info("JMS connection failed with Solace." + e.getMessage());
            e.printStackTrace();
        }
        return connection;
    }

pom.xml

<dependency>
    <groupId>com.solacesystems</groupId>
    <artifactId>sol-jms</artifactId>
    <version>10.4.0</version>
</dependency>
<dependency>
    <groupId>com.solacesystems</groupId>
    <artifactId>sol-jcsmp</artifactId>
    <version>10.4.0</version>
</dependency>

如果慰藉队列连接被中断,它不会进入异常侦听器,并且通过添加重新连接属性,它也不会在日志中显示应用程序是否正在重新连接到慰藉队列。如果安慰队列在一段时间后启动,如何重新连接到安慰队列

请帮助

4

1 回答 1

0

我建议检查您的日志级别。您正在使用 reconnectRetries 等配置正确的东西。

您应该会看到类似下面的内容。我在运行这个应用程序时得到这些日志:https ://github.com/SolaceSamples/solace-samples-spring/blob/master/spring-boot-autoconfig-receiver/src/main/java/com/solace/samples/spring /boot/SpringBootReceiver.java

[2m2021-12-01 13:45:21.742[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat started on port(s): 8081 (http) with context path ''
[2m2021-12-01 13:45:21.825[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[           main][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connecting to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (host 1 of 1, smfclient 1, attempt 1 of 1, this_host_attempt: 1 of 1)
[2m2021-12-01 13:45:21.851[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[           main][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connected to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (smfclient 1)
[2m2021-12-01 13:45:21.890[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[           main][0;39m [36mc.s.s.spring.boot.SpringBootReceiver    [0;39m [2m:[0;39m Started SpringBootReceiver in 3.494 seconds (JVM running for 4.445)
[2m2021-12-01 13:45:24.475[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[on(1)-127.0.0.1][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/]      [0;39m [2m:[0;39m Initializing Spring DispatcherServlet 'dispatcherServlet'
[2m2021-12-01 13:45:24.475[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[on(1)-127.0.0.1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Initializing Servlet 'dispatcherServlet'
[2m2021-12-01 13:45:24.477[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[on(1)-127.0.0.1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Completed initialization in 2 ms
[2m2021-12-01 13:45:46.310[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[2_ReactorThread][0;39m [36mc.s.jcsmp.impl.flow.UnbindRequestTask   [0;39m [2m:[0;39m Error Response (503) - Service Unavailable; subCode: 50; flowId=0
[2m2021-12-01 13:45:46.326[0;39m [33m WARN[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-1][0;39m [36mo.s.j.l.DefaultMessageListenerContainer [0;39m [2m:[0;39m Setup of JMS message listener invoker failed for destination 'SpringTestQueue' - trying to recover. Cause: Error receiving message - internal error (503: Unknown Queue)
[2m2021-12-01 13:45:46.332[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-1][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Channel Closed (smfclient 1)
[2m2021-12-01 13:45:46.355[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-1][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connecting to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (host 1 of 1, smfclient 2, attempt 1 of 1, this_host_attempt: 1 of 1)
[2m2021-12-01 13:45:46.370[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-1][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connected to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (smfclient 2)
[2m2021-12-01 13:45:51.390[0;39m [33m WARN[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-2][0;39m [36mo.s.j.l.DefaultMessageListenerContainer [0;39m [2m:[0;39m Setup of JMS message listener invoker failed for destination 'SpringTestQueue' - trying to recover. Cause: Error creating consumer - unknown endpoint (503: Unknown Queue)
[2m2021-12-01 13:45:51.391[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-2][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Channel Closed (smfclient 2)
[2m2021-12-01 13:45:51.397[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-2][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connecting to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (host 1 of 1, smfclient 3, attempt 1 of 1, this_host_attempt: 1 of 1)
[2m2021-12-01 13:45:51.408[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-2][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connected to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (smfclient 3)
[2m2021-12-01 13:45:56.426[0;39m [33m WARN[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-3][0;39m [36mo.s.j.l.DefaultMessageListenerContainer [0;39m [2m:[0;39m Setup of JMS message listener invoker failed for destination 'SpringTestQueue' - trying to recover. Cause: Error creating consumer - unknown endpoint (503: Unknown Queue)
[2m2021-12-01 13:45:56.427[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-3][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Channel Closed (smfclient 3)
[2m2021-12-01 13:45:56.434[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-3][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connecting to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (host 1 of 1, smfclient 4, attempt 1 of 1, this_host_attempt: 1 of 1)
[2m2021-12-01 13:45:56.441[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-3][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connected to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (smfclient 4)
[2m2021-12-01 13:46:01.454[0;39m [33m WARN[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-4][0;39m [36mo.s.j.l.DefaultMessageListenerContainer [0;39m [2m:[0;39m Setup of JMS message listener invoker failed for destination 'SpringTestQueue' - trying to recover. Cause: Error creating consumer - unknown endpoint (503: Unknown Queue)
[2m2021-12-01 13:46:01.455[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-4][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Channel Closed (smfclient 4)
[2m2021-12-01 13:46:01.463[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-4][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connecting to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (host 1 of 1, smfclient 5, attempt 1 of 1, this_host_attempt: 1 of 1)
[2m2021-12-01 13:46:01.473[0;39m [32m INFO[0;39m [35m23127[0;39m [2m---[0;39m [2m[ntContainer#0-4][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connected to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (smfclient 5)
于 2021-12-01T20:57:14.743 回答