0

I am using Tibjms jar for JMS connection and it works fine in normal case but I have problem in case the connection to jms provider is lost and then it comes back. To reproduce the issue, I performed the following steps -

  1. Connect to intranet and start the server. Works fine.

  2. Disconnect from intranet. It starts trying reconnecting the server. Fine.

  3. Connect again to intranet. It throws unknown exception and never connects again. Problem.

So, my problem is "javax.jms.JMSException: Connection unknown by server" which does not tell me much and you can see it at the end of logs.

You can see it from the following logs -

2017-10-13 15:40:52,333 [     http-nio-8080-exec-2] INFO  org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcherServlet': initialization completed in 37 ms
2017-10-13 15:41:29,293 [k Reader (Server-3285015)] ERROR com.example.jms.PaxJmsClient - Exception received from jms
javax.jms.JMSException: Disconnected from ssl://10.10.10.10:5071, will attempt to reconnect
    at com.tibco.tibjms.TibjmsConnection._invokeOnExceptionCallback(TibjmsConnection.java:2132)
    at com.tibco.tibjms.TibjmsConnection._reconnect(TibjmsConnection.java:1912)
    at com.tibco.tibjms.TibjmsConnection$ServerLinkEventHandler.onEventReconnect(TibjmsConnection.java:387)
    at com.tibco.tibjms.TibjmsxLinkTcp._doReconnect(TibjmsxLinkTcp.java:598)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.work(TibjmsxLinkTcp.java:317)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.run(TibjmsxLinkTcp.java:259)
2017-10-13 15:42:29,334 [k Reader (Server-3285015)] ERROR com.example.jms.PaxJmsClient - Exception received from jms
javax.jms.JMSException: Reconnecting to ssl://11.11.11.11:5071, attempt 1 out of 100
    at com.tibco.tibjms.TibjmsConnection._invokeOnExceptionCallback(TibjmsConnection.java:2132)
    at com.tibco.tibjms.TibjmsConnection._reconnect(TibjmsConnection.java:1975)
    at com.tibco.tibjms.TibjmsConnection$ServerLinkEventHandler.onEventReconnect(TibjmsConnection.java:387)
    at com.tibco.tibjms.TibjmsxLinkTcp._doReconnect(TibjmsxLinkTcp.java:598)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.work(TibjmsxLinkTcp.java:317)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.run(TibjmsxLinkTcp.java:259)
2017-10-13 15:42:32,335 [k Reader (Server-3285015)] ERROR com.example.jms.PaxJmsClient - Exception received from jms
javax.jms.JMSException: Reconnecting to ssl://10.10.10.10:5071, attempt 1 out of 100
    at com.tibco.tibjms.TibjmsConnection._invokeOnExceptionCallback(TibjmsConnection.java:2132)
    at com.tibco.tibjms.TibjmsConnection._reconnect(TibjmsConnection.java:1975)
    at com.tibco.tibjms.TibjmsConnection$ServerLinkEventHandler.onEventReconnect(TibjmsConnection.java:387)
    at com.tibco.tibjms.TibjmsxLinkTcp._doReconnect(TibjmsxLinkTcp.java:598)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.work(TibjmsxLinkTcp.java:317)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.run(TibjmsxLinkTcp.java:259)
2017-10-13 15:43:35,358 [k Reader (Server-3285015)] ERROR com.example.jms.PaxJmsClient - Exception received from jms
javax.jms.JMSException: Reconnecting to ssl://11.11.11.11:5071, attempt 2 out of 100
    at com.tibco.tibjms.TibjmsConnection._invokeOnExceptionCallback(TibjmsConnection.java:2132)
    at com.tibco.tibjms.TibjmsConnection._reconnect(TibjmsConnection.java:1975)
    at com.tibco.tibjms.TibjmsConnection$ServerLinkEventHandler.onEventReconnect(TibjmsConnection.java:387)
    at com.tibco.tibjms.TibjmsxLinkTcp._doReconnect(TibjmsxLinkTcp.java:598)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.work(TibjmsxLinkTcp.java:317)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.run(TibjmsxLinkTcp.java:259)
2017-10-13 15:43:38,359 [k Reader (Server-3285015)] ERROR com.example.jms.PaxJmsClient - Exception received from jms
javax.jms.JMSException: Reconnecting to ssl://10.10.10.10:5071, attempt 2 out of 100
    at com.tibco.tibjms.TibjmsConnection._invokeOnExceptionCallback(TibjmsConnection.java:2132)
    at com.tibco.tibjms.TibjmsConnection._reconnect(TibjmsConnection.java:1975)
    at com.tibco.tibjms.TibjmsConnection$ServerLinkEventHandler.onEventReconnect(TibjmsConnection.java:387)
    at com.tibco.tibjms.TibjmsxLinkTcp._doReconnect(TibjmsxLinkTcp.java:598)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.work(TibjmsxLinkTcp.java:317)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.run(TibjmsxLinkTcp.java:259)
2017-10-13 15:44:41,368 [k Reader (Server-3285015)] ERROR com.example.jms.PaxJmsClient - Exception received from jms
javax.jms.JMSException: Reconnecting to ssl://11.11.11.11:5071, attempt 3 out of 100
    at com.tibco.tibjms.TibjmsConnection._invokeOnExceptionCallback(TibjmsConnection.java:2132)
    at com.tibco.tibjms.TibjmsConnection._reconnect(TibjmsConnection.java:1975)
    at com.tibco.tibjms.TibjmsConnection$ServerLinkEventHandler.onEventReconnect(TibjmsConnection.java:387)
    at com.tibco.tibjms.TibjmsxLinkTcp._doReconnect(TibjmsxLinkTcp.java:598)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.work(TibjmsxLinkTcp.java:317)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.run(TibjmsxLinkTcp.java:259)
2017-10-13 15:44:45,951 [k Reader (Server-3285015)] ERROR com.example.jms.PaxJmsClient - Exception received from jms
javax.jms.JMSException: Reconnecting to ssl://10.10.10.10:5071, attempt 3 out of 100
    at com.tibco.tibjms.TibjmsConnection._invokeOnExceptionCallback(TibjmsConnection.java:2132)
    at com.tibco.tibjms.TibjmsConnection._reconnect(TibjmsConnection.java:1975)
    at com.tibco.tibjms.TibjmsConnection$ServerLinkEventHandler.onEventReconnect(TibjmsConnection.java:387)
    at com.tibco.tibjms.TibjmsxLinkTcp._doReconnect(TibjmsxLinkTcp.java:598)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.work(TibjmsxLinkTcp.java:317)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.run(TibjmsxLinkTcp.java:259)
2017-10-13 15:44:50,525 [k Reader (Server-3285015)] ERROR com.example.jms.PaxJmsClient - Exception received from jms
javax.jms.JMSException: Connection unknown by server
    at com.tibco.tibjms.Tibjmsx.buildException(Tibjmsx.java:659)
    at com.tibco.tibjms.TibjmsConnection._invokeOnExceptionCallback(TibjmsConnection.java:2114)
    at com.tibco.tibjms.TibjmsConnection._onDisconnected(TibjmsConnection.java:2487)
    at com.tibco.tibjms.TibjmsConnection$ServerLinkEventHandler.onEventDisconnected(TibjmsConnection.java:367)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.work(TibjmsxLinkTcp.java:328)
    at com.tibco.tibjms.TibjmsxLinkTcp$LinkReader.run(TibjmsxLinkTcp.java:259)

My code -

    @PostConstruct
    public void configurePaxJmsClient() {

        try {
            // create Topic Connection Factory
            TibjmsTopicConnectionFactory cf = new TibjmsTopicConnectionFactory(serverUrl);
            cf.setSSLTrustedCertificate(sslCertificatePath);
            cf.setSSLEnableVerifyHostName(false);
            cf.setUserName(username);
            cf.setUserPassword(password);

            cf.setReconnAttemptCount(100);
            cf.setReconnAttemptDelay(60000);
            cf.setReconnAttemptTimeout(10000);

            cf.setConnAttemptCount(100);
            cf.setConnAttemptDelay(60000);
            cf.setConnAttemptTimeout(10000);

            Tibjms.setExceptionOnFTEvents(true);
            Tibjms.setExceptionOnFTSwitch(true);

            // creation the connection and install an exception handler
            connection = cf.createTopicConnection(username, password);
            connection.setExceptionListener(this);

            // You might also use CLIENT_ACKNOWLEDGE here
            session = connection.createTopicSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
            Topic topic = session.createTopic(topicName);

            // Create the subscriber and install the listener
            TopicSubscriber ts;
            /*if (dsName == null || dsName.length() == 0) {
                ts = session.createSubscriber(topic);
            } else {
                ts = session.createDurableSubscriber(topic, dsName);
            }*/

            if (dsName == null || dsName.length() == 0) {
                ts = session.createSubscriber(topic, messageSelector, false);
            } else {
                ts = session.createDurableSubscriber(topic, dsName, messageSelector, false);
            }

            //
            ts.setMessageListener(this);
            connection.start();

        } catch (JMSException e) {
            LOGGER.error("Failed to connect with message:" + e.getMessage(), e);
            releaseResources();
        }
    }

    @Override
    public void onException(JMSException e) {
        LOGGER.error("Exception received from jms", e);
    }

Can you guys tell me what is the problem here or point me in the right direction?

Also, is this fine to have jms connection initialization in @PostConstruct of a spring bean?

Popeye
  • 1,548
  • 3
  • 25
  • 39

1 Answers1

5

Why EMS reports “reconnect failed: connection unknown for id=xxxxx”? This message indicates that the EMS server does not have or no longer has the client connections information when the client attempts to reconnect.

There are two possible reasons:

  1. Parameter “ft_reconnect_timeout” is not high enough. Before the client reconnects the server, the connection has already purged by the server. This could be resolved by setting a higher value to the “ft_reconnect_timeout” parameter in tibemsd.conf. The default value is 60 seconds.

  2. Parameter “ft_reconnect_timeout” is the amount of time (in seconds) that a backup server waits for clients to reconnect (after it assumes the role of primary server in a failover situation), this parameter specifies in seconds how long the server will keep pending connections. If a client does not reconnect within this time period, the server removes its state from the shared state files. And if the client tries to reconnect after the time set in “ft_reconnect_timeout”, the server does not have the client connections information and prints the "reconnect failed: connection unknown" message.

So will suggest you to set the value according to your environment and test the same.Also If Ft_reconnect_timeout value is high, a lot of connections and connection related objects are kept in the memory for a long time, you may have a memory issue. And if the connection is using clientID, you may run into “clientID already exists” issue.

Mahendra Andhale
  • 489
  • 8
  • 14