2013-08-05 178 views
1

我在我的應用程序中使用ActiveMQ。它的奇怪行爲在某些時候,當我啓動Tomcat服務器和左怠速運轉幾分鐘,我收到以下異常:ActiveMQ拋出NullPointerException

異常在線程「的ActiveMQ雜誌關卡工作者」顯示java.lang.NullPointerException 在組織.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:209) at org.apache.activemq.store.kahadb.MessageDatabase.checkpointUpdate(MessageDatabase.java:1349) at org.apache.activemq.store.kahadb.MessageDatabase $ 10.execute(MessageDatabase.java:814) at org.apache.kahadb.page.Transaction.execute(Transaction.java:769) at org.apache.activemq.store.kahadb.MessageDatabase.checkpointCleanup(MessageDatabase.java: 812) at org.apache.activemq.store.kahadb.MessageDatabase $ 3.run(MessageDatabase.java:324)在org.slf4j.impl

異常在線程 「ActiveMQ代理[本地主機調度器」 顯示java.lang.NullPointerException .log4jLoggerAdapter.isDebugEnabled(Log4jLoggerAdapter.java:199) at org.apache.activemq.broker.region.Queue.expireMessages(Queue.java:816) at org.apache.activemq.broker.region.Queue.access $ 100( Queue.java:96) 在org.apache.activemq.broker.region.Queue $ 2.run(Queue.java:136) 在org.apache.activemq.thread.SchedulerTimerTask.run(SchedulerTimerTask.java:33) 在java.util.TimerThread.mainLoop(Timer.java:512) java.util.TimerThread.run(Timer.java:462)

此之後,當隊列再次被調用時,它拋出異常:

捉住:無法創建傳輸。原因:javax.management.InstanceAlreadyExistsException:org.apache.activemq:BrokerName = localhost,Type = Broker javax.jms.JMSException:無法創建傳輸。原因:javax.management.InstanceAlreadyExistsException:org.apache.activemq:BrokerName =本地主機,類型=經紀人

我已經使用隊列生產者和消費者,如下所示:

製片:

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
       "vm://localhost"); 

     // Create a Connection 
     Connection connection = connectionFactory.createConnection(); 
     connection.start(); 

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

     // Create the destination (Topic or Queue) 
     Destination destination = session.createQueue(queuename); 

     // Create a MessageProducer from the Session to the Topic or Queue 
     MessageProducer producer = session.createProducer(destination); 
     producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); 

     // Create a messages 
     Iterator it = mapMessage.entrySet().iterator(); 
     MapMessage message = session.createMapMessage(); 
     while (it.hasNext()) { 
      Map.Entry pairs = (Map.Entry)it.next(); 
      message.setString(""+pairs.getKey(), ""+pairs.getValue()); 
      System.out.println(pairs.getKey() + " = " + pairs.getValue()); 
      it.remove(); // avoids a ConcurrentModificationException 
     } 

     // Tell the producer to send the message 
     System.out.println("Sent message: "+ message); 
     producer.send(message); 

     // Clean up 
     session.close(); 
     connection.close(); 

消費者:

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
       "vm://localhost"); 

     // Create a Connection 
     Connection connection = connectionFactory.createConnection(); 
     connection.start(); 

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

     // Create the destination (Topic or Queue) 
     Destination destination = session.createQueue("register"); 

     // Create a MessageConsumer from the Session to the Topic or Queue 
     MessageConsumer consumer = session.createConsumer(destination); 
     consumer.setMessageListener(this); 

ActiveMQ的集成:

PushRegisterConsumer prc = new PushRegisterConsumer(); 
    prc.start(); 

PushQueueProducer pmp = new PushQueueProducer(); 
pmp.queueProducer(AppConstants.QUEUE_NAME,registerDetails); 

的生產和消費已經融入如上圖所示

請幫我解決這個問題。

感謝,

卡菲基恩

+0

你可以提供一些有關ActiveMQ如何連接到你的應用程序的信息?從它的聲音,你有一個嵌入式經紀人 - 是嗎?你也可以請你發佈你的ActiveMQ配置。 –

+0

嗨傑克。感謝您的回覆。用必要的信息修改了我的問題。請提供您的意見。 –

回答

0

創建ActiveMQConnectionFactory一次,並把它傳遞到PushRegisterConsumerPushRegisterProducer的構造函數。目前,看起來有2個嵌入式經紀商正在創建,名稱爲localhost - 您希望確保這僅僅發生一次。

相關問題