When your subscriber shows as being offline, does JMX still show that the connection is open? Or are you indeed closing the connection?
Tim On Jul 12, 2017 12:39 AM, "tejas13" <[email protected]> wrote: > > Hi All, > > Thank in Advance. > > Previously we were using version 5.12.0. That time my code was working > fine. > Subscriber never get offline automatically. > > Recently we upgraded to version 5.14.5 as most stable version and new > features > > I found that my Active Durable Subscriber status is changing automatically > to offline Durable Subscriber. > > I am using below code for connection. > > public class ReceiverFor_ECRE_TO_SEQ_Topic { > private static final Logger logger = > Logger.getLogger(ReceiverFor_ECRE_TO_SEQ_Topic.class); > > private TopicSession qsen = null; > private String JNDI_PROVIDER_URL = null; > private String topicName = null; > private String jmsUid = null; > private String jmsPwd = null; > private Topic topic = null; > private ConnectionFactory connFactory; > private TopicConnection queueConn; > > public ReceiverFor_ECRE_TO_SEQ_Topic(String topicName, String > JNDI_PROVIDER_URL, String jmsUid, String jmsPwd) { > this.topicName = topicName; > this.JNDI_PROVIDER_URL = JNDI_PROVIDER_URL; > this.jmsUid = jmsUid; > this.jmsPwd = jmsPwd; > } > > public void listenTopic() { > try { > Properties env = new Properties(); > env.put(Context.INITIAL_CONTEXT_FACTORY, > Constants.INITIAL_CONTEXT_FACTORY); > env.put(Context.PROVIDER_URL, > System.getProperty(Context.PROVIDER_URL, > JNDI_PROVIDER_URL)); > env.put(Context.SECURITY_PRINCIPAL, jmsUid); > env.put(Context.SECURITY_CREDENTIALS, jmsPwd); > env.setProperty("prefetchPolicy.durableTopicPrefetch", > "1000"); > InitialContext inictx = new InitialContext(env); > > // lookup the queue object > topic = (Topic) inictx.lookup(topicName); > // lookup the topic connection factory > connFactory = (ConnectionFactory) > inictx.lookup(Constants.CONN_FACTORY); > > // System.out.println("1"); > if (setupJMS()) { > > isJMSConnected = true; > /* > * while(true) { } > */ > } else { > > listenTopic(); > > } > } catch (NamingException ex) { > // ex.printStackTrace(); > logger.error("Unable to connect Server for ECRE > Topic"); > > try { > Thread.sleep(5000); > listenTopic(); > } catch (InterruptedException ex1) { > // ex.printStackTrace(); > logger.error("Unable to connect Server > for ECRE Topic"); > } > } > } > > public boolean setupJMS() > { > try { > > // create a queue connection > String consumerName = > ResourceBundleHelper.applicationData.get(ApplicationConstants.ECRE_TO_ > SEQ_TOPIC_CONSUMER_Id); > > queueConn = (TopicConnection) > connFactory.createConnection(); > queueConn.setClientID(consumerName); > > // create a queue session > // if (null == this.qsen) > { > this.qsen = queueConn.createTopicSession( > false, > Session.CLIENT_ACKNOWLEDGE); > } > this.queueConn.setExceptionListener(new > ConnectionExceptionListner()); > MessageListenerFor_ECRE_TO_SEQ_Topic temp = new > MessageListenerFor_ECRE_TO_SEQ_Topic(); > // create a queue subscriber > > // MessageConsumer queueReceiver = > qsen.createConsumer(topic); > MessageConsumer queueReceiver = > qsen.createDurableSubscriber(topic, > consumerName); > > queueReceiver.setMessageListener(temp); > queueConn.start(); > } catch (Exception e) > { > logger.error(" ReceiverFor_ECRE_TO_SEQ_Topic Setup > JMS Exception -" + > e.getMessage()); > > //System.gc(); > try > { > Thread.sleep(60000); > } > catch(Exception er) > { > logger.error("Exception occured in > Thread.sleep"); > } > return false; > } > return true; > } > > private volatile boolean isJMSConnected = false; > > private class ConnectionExceptionListner implements > ExceptionListener { > @Override > public void onException(JMSException exception) { > isJMSConnected = false; > > while (true) { > cleanUp(); > isJMSConnected = setupJMS(); > > if (isJMSConnected) > { > return; > } else { > > try { > //System.gc(); > > Thread.sleep(2*60*1000); > } catch (Exception e) { > System.out.println(" > "+e.getMessage()); > } > } > } > } > } > > private void cleanUp() { > try { > this.queueConn.setExceptionListener(null); > } catch (Exception e) { > // System.out.println("Exception in cleanUP()" + > e.getMessage()); > logger.error(" ReceiverFor_ECRE_TO_SEQ_Topic > Exception in JMS cleanUP()" > + e.getMessage()); > > } > try { > this.queueConn.close(); > } catch (Exception e) { > // System.out.println("Exception in connection > close()" + > // e.getMessage()); > logger.error(" ReceiverFor_ECRE_TO_SEQ_Topic > Exception in JMS connection > close()" + e.getMessage()); > > } > } > > } > > > > > -- > View this message in context: http://activemq.2283324.n4. > nabble.com/Active-Durable-Subscriber-status-automatically-changing-to- > offline-Durable-Subscriber-5-14-1-Most-St-tp4728482.html > Sent from the ActiveMQ - User mailing list archive at Nabble.com. >
