当前位置: 首页 > 知识库问答 >
问题:

Spring Boot重新连接solace jms队列

赫连华皓
2023-03-14

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

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

波姆。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>

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

好心帮忙

共有1个答案

范翰池
2023-03-14

我建议您检查日志级别。您正在使用重新连接重试等配置正确的东西。

您应该看到下面这样的内容。运行此应用程序时,我会获取这些日志: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)
 类似资料:
  • 在从sping-引导1.5. x切换到sping-引导-2. x后,当db连接关闭时,我的Spring应用程序会不断尝试重新连接到数据库。我甚至无法调用运行状况检查endpoint。 这只发生在spring-boot-2.x中 它可能会尝试重新连接,但就我而言,它不应该阻止整个应用程序。 application.yml pom.xml 当数据库关闭时,我得到以下错误的泛滥。 错误

  • 重新建立mqtt连接,前提是必须已经通过Iot_id,Iot_pwd建立过一次mqtt连接。 请求方式: "|4|1|5|\r" 返回值: "|4|1|1|1|\r" mqtt连接状态:连接成功 "|4|1|1|2|reason|\r" mqtt连接状态:连接失败,字符串reason表示失败的原因 Arduino样例: softSerial.print("|4|1|5|\r");

  • 重新连接上一次连接的wifi。 请求方式: "|2|3|\r" 返回值: "|2|1|\r" wifi连接状态:wifi断开连接 "|2|2|\r" wifi连接状态:正在连接wifi "|2|3|ip|\r" wifi连接状态:wifi连接成功,返回OBLOQ的ip地址 "|2|4|\r" wifi连接状态:wifi连接失败,检查SSID和PWD是否输入正确 Arduino样例: softSer

  • 我使用rabbitMQ作为代理,在spring中配置了生产者/消费者应用程序(配置如下所述)。当消费者机器出现故障时,我面临重新连接消费者的问题,消费者应用程序通常会在一段时间内恢复,但代理(队列)和消费者之间的连接没有重新建立, 我在rabbit-MQ管理控制台中进行了验证,发现队列中没有列出任何消费者,尽管消费者在一段时间后已经自动恢复。 任何关于如何解决这个问题的见解,请让我知道,如果需要任

  • 问题内容: 在生产中,我有一个使用连接局部变量保存游戏状态的游戏。但是,我注意到,如果我在连接上闲置了一段时间,它将断开连接并重新连接,这将丢失当前状态。在本地主机上进行测试时,我从未注意到此行为。这是套接字连接的规范行为,还是导致连接断开的其他原因。 如果是正常行为,通常如何处理?是否应该将连接值全局存储,以便用户断开/重新连接时可以恢复连接值? 问题答案: 您的问题与套接字超时有关。如果某个套

  • 我正在使用spring jms在独立应用程序中加载spring应用程序(使用spring 2.5,无法升级到3.0),如下所示 下面是我的申请ontext.xml 现在,问题是默认情况下DefaultMessageListenerContainer会尝试恢复与queue的连接,直到成功,我可以在下面的日志文件中看到消息 但我的要求是,如果它无法连接我的应用程序上下文应该停止加载,我可以报告一个错误