2014-08-29 2 views
1

JMS MessageConsumer를 유지하려고 시도하면 ActiveMQ가 재부팅되므로 Failover Transport 프로토콜을 사용하여 다시 연결할 수 있습니다.MessageListener를 사용하는 JMS MessageConsumer가 ActiveMQ 종료시 종료 됨

그러나 ActiveMQ가 종료되면 종료됩니다.

내가 다음 받는다는 종속성을 사용

이보고 "해결"된 버그처럼 보이지만 난 여전히 ActiveMQ를 5.10.0의 최신 버전에서이 문제를보고 있어요

<dependency> 
     <groupId>org.apache.activemq</groupId> 
     <artifactId>activemq-all</artifactId> 
     <version>5.10.0</version> 
    </dependency> 

여기에 사용하는 몇 가지 예제 코드는

public class SimpleConsumer { 

public static void main(String[] args) throws Exception { 
    String url = "failover:(tcp://ACTIVE_MQ_HOST:61616)"; 
    String destination = "test-topic"; 

    TopicConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
      url); 

    ActiveMQConnection connection = (ActiveMQConnection) connectionFactory 
      .createConnection(); 

    Session session = connection.createSession(false, 
      Session.AUTO_ACKNOWLEDGE); 

    Topic topic = session.createTopic(destination); 

    MessageConsumer consumer = session.createConsumer(topic); 
    connection.start(); 

// Uncomment these lines and comment out the lines below and it will work 
//  while (true) { 
//   Message msg = consumer.receive(); 
//   if (msg instanceof TextMessage) { 
//    System.out.println("msg received = " + msg); 
//   } 
//  } 

    consumer.setMessageListener(new MessageListener() { 

     public void onMessage(Message msg) { 
      System.out.println("msg received = " + msg); 
     } 

    }); 

} 

}

나는 것 MessageListener와 함께 작동하는 것처럼 비 차단 및 비동기입니다.

이 문제에 대한 도움을 주시면 대단히 감사하겠습니다.

내가 이미 JIRA에서 제안한대로 시도한 것은 데몬이 아닌 스레드에서이 작업을 실행하는 것이지만 작동하지 않습니다.

나는 스레드가) (실행 후 종료 메소드가 완료 한 다음 이전 실행하는 비 데몬 스레드가 없기 때문에 작동하지 않는 스레드 솔루션이이

public class SimpleConsumerThread { 

    public static void main(String[] args) throws Exception { 


     Thread t = new Thread() { 
      public void run() { 
       try {    
        String url = "failover:(tcp://ACTIVEMQ_HOST:61616)"; 
        String destination = "test-topic"; 

        TopicConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); 

        ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection(); 

        Session session = connection.createSession(false, 
        Session.AUTO_ACKNOWLEDGE); 

        Topic topic = session.createTopic(destination); 

        MessageConsumer consumer = session.createConsumer(topic); 
        connection.start(); 
        consumer.setMessageListener(new MessageListener() { 

         public void onMessage(Message msg) { 
          System.out.println("msg received = " + msg); 
         } 

        }); 
       } catch (JMSException e) { 
        e.printStackTrace(); 
       }    
      } 
     }; 
     t.setDaemon(false); 

     t.start(); 

    } 

} 

답변

1

이유를 시도 . 타사 라이브러리의 내부 스레딩 모델을 사용하여 응용 프로그램을 계속 실행하는 것이 좋습니다.

ActiveMQ 클라이언트의 버그 또는 다른 구성 복잡성에 관계없이 작동하는 최상의 솔루션은 주 스레드를 유지하기 위해 while (true) sleep() 패러다임을 사용하는 것입니다.

1

감사합니다 팀,

예 그했다. 방금 추가 한 적어도 하나의 사용자 스레드가 살아 있도록 프로그램이 나던.

while(true) { 
     Thread.sleep(1000); 
    } 

환호,

public class SimpleConsumer { 

    static Logger logger = Logger.getLogger(SimpleConsumer.class); 

    public static void main(String[] args) throws Exception { 
     String url = "failover:(tcp://sydapp057lx.fxdms.net:61615)"; 
     String destination = "test-topic"; 

     TopicConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
       url); 

     ActiveMQConnection connection = (ActiveMQConnection) connectionFactory 
       .createConnection(); 

     connection.setExceptionListener(new ExceptionListener() { 
      public void onException(JMSException e) { 
       logger.debug("got exception = " + e); 
      } 
     }); 

     Session session = connection.createSession(false, 
       Session.AUTO_ACKNOWLEDGE); 

     Topic topic = session.createTopic(destination); 

     MessageConsumer consumer = session.createConsumer(topic); 
     connection.start(); 

     consumer.setMessageListener(new MessageListener() { 

      public void onMessage(Message msg) { 
       logger.debug("msg received = " + msg); 
      } 

     }); 

     while(true) { 
      Thread.sleep(1000); 
     } 

    } 


} 
관련 문제