アプリケーションで ActiveMQ を使用しています。Tomcat サーバーを起動して数分間アイドル状態のままにしておくと、ある時点で奇妙な動作が発生し、次の例外が発生します。
org.apache.activemq.store.kahadb.MessageDatabase.checkpointUpdate(MessageDatabase.java: 1349) org.apache.activemq.store.kahadb.MessageDatabase$10.execute(MessageDatabase.java:814) で org.apache.kahadb.page.Transaction.execute(Transaction.java:769) で org.apache.activemq. org.apache.activemq.store.kahadb.MessageDatabase$3.run(MessageDatabase.java:324) の store.kahadb.MessageDatabase.checkpointCleanup(MessageDatabase.java:812)
org.apache.activemq.broker.region.Queue.expireMessages(Queue. java:816) org.apache.activemq.broker.region.Queue.access$100(Queue.java:96) で org.apache.activemq.broker.region.Queue$2.run(Queue.java:136) で.apache.activemq.thread.SchedulerTimerTask.run(SchedulerTimerTask.java:33) at java.util.TimerThread.mainLoop(Timer.java:512) at 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=localhost,Type=Broker
以下に示すように、キューのプロデューサーとコンシューマーを使用しました。
プロデューサー:
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);
上記のようにプロデューサーとコンシューマーが統合されました
この問題の解決を手伝ってください。
ありがとう、
カーティケヤン