コード例 #1
0
  /**
   * Tries to reconnect to the durable topic. This method blocks until the try is successful or this
   * provider is stopped.
   */
  private void reconnect() {
    for (; ; ) {

      if (stopped) {
        return;
      }
      try {
        // close subscriber if not previously closed
        if (subscriber != null) {
          subscriber.close();
        }
        if (connection != null) {
          connection.close();
        }
        connection = connectionFactory.createTopicConnection();
        if (clientID != null) {
          connection.setClientID(clientID);
        }
        TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = topicFactory.createTopic(topicName);
        subscriber = session.createDurableSubscriber(topic, name);
        connection.start();
        return;
      } catch (JMSException e) {
        logger.error("could not connect to durable topic, topic: " + topicName, e);
        // step back for a while
        backOffAfterJMSException(e);
      }
    }
  }