JMS の送受信に ActiveMQ 5.9.0 を使用しています。まず、MapMessage をキューに送信します。
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("my-queue");
MessageProducer producer = session.createProducer(destination);
MapMessage message = session.createMapMessage();
message.setDouble(key, value);
producer.send(message);
session.commit();
session.close();
connection.close();
System.out.println(message);
印刷される内容は次のとおりです。
ActiveMQMapMessage {commandId = 0、responseRequired = false、messageId = ID:LT006632-52708-1382520875674-11:1:1:1:1、originalDestination = null、originalTransactionId = null、producerId = null、destination = queue://my-キュー、transactionId = TX:ID:LT006632-52708-1382520875674-11:1:1、有効期限 = 0、タイムスタンプ = 1382520891291、到着 = 0、brokerInTime = 0、brokerOutTime = 0、correlationId = null、replyTo = null、persistent = true、type = null、priority = 4、groupID = null、groupSequence = 0、targetConsumerId = null、compressed = false、userID = null、content = org.apache.activemq.util.ByteSequence@33cf4、marshalledProperties = null、dataStructure = null、redeliveryCounter = 0、サイズ = 0、プロパティ = null、readOnlyProperties = false、readOnlyBody = false、droppable = false、jmsXGroupFirstForConsumer = false} ActiveMQMapMessage{ theTable = {entry 6=922.0} }
メッセージ内の正しい theTable を使用してください。
この方法で別のプロジェクトでメッセージを受け取ります。
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
Connection connection = connectionFactory.createConnection();
connection.start();
final Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("my-queue");
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
public void onMessage(Message msg) {
MapMessage message = (MapMessage) msg;
// TODO something....
try {
System.out.println(message.getJMSType());
session.commit();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Thread.sleep(30000);
session.close();
connection.close();
ただし、メッセージを受信すると、次のように出力されます。
ActiveMQMapMessage {commandId = 6、responseRequired = false、messageId = ID:LT006632-52708-1382520875674-11:1:1:1:1、originalDestination = null、originalTransactionId = null、producerId = ID:LT006632-52708-1382520875674-11: 1:1:1、宛先 = queue://my-queue、transactionId = TX:ID:LT006632-52708-1382520875674-11:1:1、有効期限 = 0、タイムスタンプ = 1382520891291、到着 = 0、brokerInTime = 1382520891291、 brokerOutTime = 1382520891298、correlationId = null、replyTo = null、persistent = true、type = null、priority = 4、groupID = null、groupSequence = 0、targetConsumerId = null、compressed = false、userID = null、content = org.apache. activemq.util.ByteSequence@186db54、marshalledProperties = null、dataStructure = null、redeliveryCounter = 0、サイズ = 0、プロパティ = null、readOnlyProperties = true、readOnlyBody = true、droppable = false、jmsXGroupFirstForConsumer = false} ActiveMQMapMessage{ theTable = {} }
空の theTable アイテムを使用。何が原因で、この問題を解決する方法を知りたいです。ありがとう!