2013-08-05 135 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 - 您希望确保这仅仅发生一次。

相关问题