骆驼,带有 spring jndi 模板的 solace jndi 配置在无法访问 solace 时不会抛出异常

camel, solace jndi configuration with spring jndi template not throwing exception when solace not reachable

我正在尝试使用 camel-jms 和 spring 连接到 solace broker。我的微服务将使用 REST 输入并将安慰队列加入队列。

我面临的问题是,当连接中断时,处理线程正在无限等待连接建立,而不是抛出错误。

并且在客户端调用 REST 服务时超时..

Spring 配置:

     <bean id="Solace.JndiTemplateDev"
          class="org.springframework.jndi.JndiTemplate">
        <property name="environment">
            <props>
                <prop key="java.naming.provider.url">smf://_url_:port</prop>
                <prop key="java.naming.factory.initial">com.solacesystems.jndi.SolJNDIInitialContextFactory</prop>
                <prop key="java.naming.security.principal">xxxx</prop>
                <prop key="java.naming.security.credentials">xxxxxx</prop>
                <prop key="Solace_JMS_JNDI_ConnectRetries">0</prop>
                <prop key="Solace_JMS_JNDI_ReadTimeout">10000</prop>
                <prop key="Solace_JMS_JNDI_ReconnectRetries">2</prop>
                <prop key="Solace_JMS_JNDI_ConnectTimeout">5000</prop>
            </props>
        </property>
    </bean>

    <bean id="Solace.JndiObjectFactoryBeanDev"
          class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate" ref="Solace.JndiTemplateDev"/>
        <property name="jndiName" value="defaultConnectionFactory"/>
        <property name="lookupOnStartup" value="false"/>
        <property name="proxyInterface" value="javax.jms.ConnectionFactory"/>
    </bean>

    <bean id="Solace.CachedConnectionFactoryDev" primary="true"
          class="org.springframework.jms.connection.CachingConnectionFactory">
        <property name="targetConnectionFactory" ref="Solace.JndiObjectFactoryBeanDev"/>
        <property name="reconnectOnException" value="true"/> 
        <property name="sessionCacheSize" value="5"/>
    </bean>


    <bean id="dynamicDestinationResolverDev"
        class="org.springframework.jms.support.destination.DynamicDestinationResolver">
    </bean>

    <bean id="jmsSolaceBhPDEV" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="Solace.CachedConnectionFactoryDev"/>
        <property name="destinationResolver" ref="dynamicDestinationResolverDev"/>

    </bean>

请查找日志。

19.11.18 22:55:30.641 DEBUG     http-nio-8080-exec-3  com.solacesystems.jms.SolSession  qa | Entering createQueue()
19.11.18 22:55:30.643  INFO     http-nio-8080-exec-3 mp.protocol.impl.TcpClientChannel  qa | TcpClientChannel:open(isReconn=false) while connected, return.
19.11.18 22:55:30.644 DEBUG     http-nio-8080-exec-3 mp.protocol.impl.TcpClientChannel  qa | doSmfSharedReq (smfclient 4) try=0 / max=1 
19.11.18 22:55:48.937  INFO Thread_reconnect_service mp.protocol.impl.TcpClientChannel  qa | Connection attempt failed to host 'abc.com' ReconnectException com.solacesystems.jcsmp.JCSMPTransportException: (Client name: localhost/19108/#00560002/xnuvPhoyFH   Local port: -1   Remote addr: abc.com:55555) - Error communicating with the router. cause: java.net.ConnectException: Connection timed out: no further information
19.11.18 22:55:51.939 DEBUG Thread_reconnect_service csmp.protocol.smf.SimpleSmfClient  qa | Local port: -1   Remote addr: abc.com:55555(smfclient 4) Closing socket
19.11.18 22:55:51.940  INFO Thread_reconnect_service mp.protocol.impl.TcpClientChannel  qa | Connecting to host 'orig=tcp://abc.com:55555, scheme=tcp://, host=abc.com, port=55555' (host 1 of 1, smfclient 4, attempt 2 of 2147483647, this_host_attempt: 1 of 2)
19.11.18 22:55:51.941 DEBUG Thread_reconnect_service ocol.impl.ChannelOpStrategyClient  qa | [JCSMPSession[testErrorHandlerUser@tcp://abc.com:55555] (0002)] Opening TcpClientChannel.
19.11.18 22:55:51.943 DEBUG Thread_reconnect_service csmp.protocol.smf.SimpleSmfClient  qa | Local port: -1   Remote addr: abc.com:55555Correlation tag not found in message, adding one: 13
19.11.18 22:55:51.944 DEBUG Thread_reconnect_service csmp.protocol.smf.SimpleSmfClient  qa | Local port: -1   Remote addr: abc.com:55555(smfclient 4) Attempting to open socket, host=abc.com, port=55555
19.11.18 22:55:51.962  INFO Thread_reconnect_service mp.protocol.impl.TcpClientChannel  qa | Connection attempt failed to host 'abc.com' ReconnectException com.solacesystems.jcsmp.JCSMPTransportException: (Client name: localhost/19108/#00560002/xnuvPhoyFH   Local port: -1   Remote addr: abc.com:55555) - Error communicating with the router. cause: java.net.UnknownHostException
19.11.18 22:55:54.964 DEBUG Thread_reconnect_service csmp.protocol.smf.SimpleSmfClient  qa | Local port: -1   Remote addr: abc.com:55555(smfclient 4) Closing socket
19.11.18 22:55:54.966  INFO Thread_reconnect_service mp.protocol.impl.TcpClientChannel  qa | Connecting to host 'orig=tcp://abc.com:55555, scheme=tcp://, host=abc.com, port=55555' (host 1 of 1, smfclient 4, attempt 2 of 2147483647, this_host_attempt: 2 of 2)
19.11.18 22:55:54.967 DEBUG Thread_reconnect_service ocol.impl.ChannelOpStrategyClient  qa | [JCSMPSession[testErrorHandlerUser@tcp://abc.com:55555] (0002)] Opening TcpClientChannel.
19.11.18 22:55:54.969 DEBUG Thread_reconnect_service csmp.protocol.smf.SimpleSmfClient  qa | Local port: -1   Remote addr: abc.com:55555Correlation tag not found in message, adding one: 14
19.11.18 22:55:54.970 DEBUG Thread_reconnect_service csmp.protocol.smf.SimpleSmfClient  qa | Local port: -1   Remote addr: abc.com:55555(smfclient 4) Attempting to open socket, host=abc.com, port=55555
19.11.18 22:55:54.972  INFO Thread_reconnect_service mp.protocol.impl.TcpClientChannel  qa | Connection attempt failed to host 'abc.com' ReconnectException com.solacesystems.jcsmp.JCSMPTransportException: (Client name: localhost/19108/#00560002/xnuvPhoyFH   Local port: -1   Remote addr: abc.com:55555) - Error communicating with the router. cause: java.net.UnknownHostException
19.11.18 22:55:57.975 DEBUG Thread_reconnect_service csmp.protocol.smf.SimpleSmfClient  qa | Local port: -1   Remote addr: abc.com:55555(smfclient 4) Closing socket
19.11.18 22:55:57.977  INFO Thread_reconnect_service mp.protocol.impl.TcpClientChannel  qa | Connecting to host 'orig=tcp://abc.com:55555, scheme=tcp://, host=abc.com, port=55555' (host 1 of 1, smfclient 4, attempt 3 of 2147483647, this_host_attempt: 1 of 2)
19.11.18 22:55:57.978 DEBUG Thread_reconnect_service ocol.impl.ChannelOpStrategyClient  qa | [JCSMPSession[testErrorHandlerUser@tcp://abc.com:55555] (0002)] Opening TcpClientChannel.
19.11.18 22:55:57.981 DEBUG Thread_reconnect_service csmp.protocol.smf.SimpleSmfClient  qa | Local port: -1   Remote addr: abc.com:55555Correlation tag not found in message, adding one: 15
19.11.18 22:55:57.982 DEBUG Thread_reconnect_service csmp.protocol.smf.SimpleSmfClient  qa | Local port: -1   Remote addr: abc.com:55555(smfclient 4) Attempting to open socket, host=abc.com, port=55555
19.11.18 22:55:57.983  INFO Thread_reconnect_service mp.protocol.impl.TcpClientChannel  qa | Connection attempt failed to host 'abc.com' ReconnectException com.solacesystems.jcsmp.JCSMPTransportException: (Client name: localhost/19108/#00560002/xnuvPhoyFH   Local port: -1   Remote addr: abc.com:55555) - Error communicating with the router. cause: java.net.UnknownHostException

看起来您可能已经在 Solace 端的连接工厂中将连接重试 属性 配置为“-1”。这将导致应用程序无限期重试。

在您的应用程序中,您已经为 JNDI 连接配置了适当的重新连接设置,但没有为数据连接配置。

必须在连接工厂的 Solace 端设置数据连接重新连接属性。 (https://docs.solace.com/Solace-JMS-API/Data-Connection-Properti.htm)