本文整理汇总了Java中javax.jms.MapMessage类的典型用法代码示例。如果您正苦于以下问题:Java MapMessage类的具体用法?Java MapMessage怎么用?Java MapMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MapMessage类属于javax.jms包,在下文中一共展示了MapMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import javax.jms.MapMessage; //导入依赖的package包/类
/**
* 使用jmsTemplate的send/MessageCreator()发送Map类型的消息并在Message中附加属性用于消息过滤.
*/
private void sendMessage(final User user, Destination destination) {
jmsTemplate.send(destination, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
MapMessage message = session.createMapMessage();
message.setString("userName", user.getName());
message.setString("email", user.getEmail());
message.setStringProperty("objectType", "user");
return message;
}
});
}
示例2: makeMessage
import javax.jms.MapMessage; //导入依赖的package包/类
protected Message makeMessage(Session session, ModelService modelService, Map<String, Object> context)
throws GenericServiceException, JMSException {
List<String> outParams = modelService.getParameterNames(ModelService.OUT_PARAM, false);
if (UtilValidate.isNotEmpty(outParams))
throw new GenericServiceException("JMS service cannot have required OUT parameters; no parameters will be returned.");
String xmlContext = null;
try {
if (Debug.verboseOn()) Debug.logVerbose("Serializing Context --> " + context, module);
xmlContext = JmsSerializer.serialize(context);
} catch (Exception e) {
throw new GenericServiceException("Cannot serialize context.", e);
}
MapMessage message = session.createMapMessage();
message.setString("serviceName", modelService.invoke);
message.setString("serviceContext", xmlContext);
return message;
}
示例3: testMapConversion
import javax.jms.MapMessage; //导入依赖的package包/类
@Test
public void testMapConversion() throws JMSException {
Session session = mock(Session.class);
MapMessage message = mock(MapMessage.class);
Map<String, String> content = new HashMap<String, String>(2);
content.put("key1", "value1");
content.put("key2", "value2");
given(session.createMapMessage()).willReturn(message);
given(message.getMapNames()).willReturn(Collections.enumeration(content.keySet()));
given(message.getObject("key1")).willReturn("value1");
given(message.getObject("key2")).willReturn("value2");
SimpleMessageConverter converter = new SimpleMessageConverter();
Message msg = converter.toMessage(content, session);
assertEquals(content, converter.fromMessage(msg));
verify(message).setObject("key1", "value1");
verify(message).setObject("key2", "value2");
}
示例4: testMapConversionWhereMapHasNonStringTypesForKeys
import javax.jms.MapMessage; //导入依赖的package包/类
@Test
public void testMapConversionWhereMapHasNonStringTypesForKeys() throws JMSException {
MapMessage message = mock(MapMessage.class);
final Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
final Map<Integer, String> content = new HashMap<Integer, String>(1);
content.put(1, "value1");
final SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) { /* expected */ }
}
示例5: testConsumeMapMessage
import javax.jms.MapMessage; //导入依赖的package包/类
@Test
public void testConsumeMapMessage() throws Exception {
endpoint.expectedMessageCount(1);
jmsTemplate.setPubSubDomain(false);
jmsTemplate.send("test.map", new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
MapMessage mapMessage = session.createMapMessage();
mapMessage.setString("foo", "abc");
mapMessage.setString("bar", "xyz");
return mapMessage;
}
});
endpoint.assertIsSatisfied();
assertCorrectMapReceived();
}
示例6: assertCorrectMapReceived
import javax.jms.MapMessage; //导入依赖的package包/类
protected void assertCorrectMapReceived() {
Exchange exchange = endpoint.getReceivedExchanges().get(0);
// This should be a JMS Exchange
assertNotNull(ExchangeHelper.getBinding(exchange, JmsBinding.class));
JmsMessage in = (JmsMessage) exchange.getIn();
assertNotNull(in);
Map<?, ?> map = exchange.getIn().getBody(Map.class);
log.info("Received map: " + map);
assertNotNull("Should have received a map message!", map);
assertIsInstanceOf(MapMessage.class, in.getJmsMessage());
assertEquals("map.foo", "abc", map.get("foo"));
assertEquals("map.bar", "xyz", map.get("bar"));
assertEquals("map.size", 2, map.size());
}
示例7: onMessage
import javax.jms.MapMessage; //导入依赖的package包/类
/**
* MessageListener回调函数.
*/
@Override
public void onMessage(Message message) {
try {
MapMessage mapMessage = (MapMessage) message;
// 打印消息详情
logger.info("UserName:{}, Email:{}", mapMessage.getString("userName"), mapMessage.getString("email"));
// 发送邮件
// if (simpleMailService != null) {
// simpleMailService.sendNotificationMail(mapMessage.getString("userName"));
// }
} catch (Exception e) {
logger.error("处理消息时发生异常.", e);
}
}
示例8: convert
import javax.jms.MapMessage; //导入依赖的package包/类
/**
* This implementation converts a TextMessage back to a String, a
* ByteMessage back to a byte array, a MapMessage back to a Map,
* and an ObjectMessage back to a Serializable object. Returns
* the plain Message object in case of an unknown message type.
*
* @return payload
* @throws javax.jms.JMSException
*/
@Override
public Object convert(Message message) throws JMSException
{
if (message instanceof TextMessage) {
return ((TextMessage)message).getText();
} else if (message instanceof StreamMessage) {
return ((StreamMessage)message).readString();
} else if (message instanceof BytesMessage) {
return extractByteArrayFromMessage((BytesMessage)message);
} else if (message instanceof MapMessage) {
return extractMapFromMessage((MapMessage)message);
} else if (message instanceof ObjectMessage) {
return extractSerializableFromMessage((ObjectMessage)message);
} else {
return message;
}
}
示例9: print
import javax.jms.MapMessage; //导入依赖的package包/类
public static void print(Message msg) throws JMSException {
log.info(".print received message: " + msg.getJMSMessageID());
if (msg instanceof ObjectMessage) {
ObjectMessage objMsg = (ObjectMessage) msg;
log.info(".print object: " + objMsg.getObject().toString());
} else {
MapMessage mapMsg = (MapMessage) msg;
HashMap map = new HashMap();
Enumeration en = mapMsg.getMapNames();
while (en.hasMoreElements()) {
String property = (String) en.nextElement();
Object mapObject = mapMsg.getObject(property);
map.put(property, mapObject);
}
log.info(".print map: " + map);
}
}
示例10: testSendNullMapMessage
import javax.jms.MapMessage; //导入依赖的package包/类
@Test
public void testSendNullMapMessage() throws Exception {
try (Connection connection = factory.createConnection()) {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(queueName);
System.out.println("Queue:" + queue);
MessageProducer producer = session.createProducer(queue);
MessageConsumer consumer = session.createConsumer(queue);
producer.send(session.createMapMessage());
Assert.assertNull(consumer.receive(100));
connection.start();
MapMessage message = (MapMessage) consumer.receive(5000);
Assert.assertNotNull(message);
message.acknowledge();
}
}
示例11: sendCompressedMapMessageUsingOpenWire
import javax.jms.MapMessage; //导入依赖的package包/类
private void sendCompressedMapMessageUsingOpenWire() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);
MapMessage mapMessage = session.createMapMessage();
mapMessage.setBoolean("boolean-type", true);
mapMessage.setByte("byte-type", (byte) 10);
mapMessage.setBytes("bytes-type", TEXT.getBytes());
mapMessage.setChar("char-type", 'A');
mapMessage.setDouble("double-type", 55.3D);
mapMessage.setFloat("float-type", 79.1F);
mapMessage.setInt("int-type", 37);
mapMessage.setLong("long-type", 56652L);
mapMessage.setObject("object-type", new String("VVVV"));
mapMessage.setShort("short-type", (short) 333);
mapMessage.setString("string-type", TEXT);
producer.send(mapMessage);
}
示例12: extractString
import javax.jms.MapMessage; //导入依赖的package包/类
@Override
protected String extractString(JMSBindingData binding) throws Exception {
Message content = binding.getMessage();
if (content instanceof TextMessage) {
return TextMessage.class.cast(content).getText();
} else if (content instanceof BytesMessage) {
BytesMessage sourceBytes = BytesMessage.class.cast(content);
if (sourceBytes.getBodyLength() > Integer.MAX_VALUE) {
throw JCAMessages.MESSAGES.theSizeOfMessageContentExceedsBytesThatIsNotSupportedByThisOperationSelector("" + Integer.MAX_VALUE);
}
byte[] bytearr = new byte[(int)sourceBytes.getBodyLength()];
sourceBytes.readBytes(bytearr);
return new String(bytearr);
} else if (content instanceof ObjectMessage) {
ObjectMessage sourceObj = ObjectMessage.class.cast(content);
return String.class.cast(sourceObj.getObject());
} else if (content instanceof MapMessage) {
MapMessage sourceMap = MapMessage.class.cast(content);
return sourceMap.getString(KEY);
} else {
return content.getStringProperty(KEY);
}
}
示例13: testBrokerStats
import javax.jms.MapMessage; //导入依赖的package包/类
public void testBrokerStats() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue replyTo = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(replyTo);
Queue query = session.createQueue(StatisticsBroker.STATS_BROKER_PREFIX);
MessageProducer producer = session.createProducer(query);
Message msg = session.createMessage();
msg.setJMSReplyTo(replyTo);
producer.send(msg);
MapMessage reply = (MapMessage) consumer.receive(10 * 1000);
assertNotNull(reply);
assertTrue(reply.getMapNames().hasMoreElements());
assertTrue(reply.getJMSTimestamp() > 0);
assertEquals(Message.DEFAULT_PRIORITY, reply.getJMSPriority());
/*
for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
String name = e.nextElement().toString();
System.err.println(name+"="+reply.getObject(name));
}
*/
}
示例14: testDestinationStats
import javax.jms.MapMessage; //导入依赖的package包/类
public void testDestinationStats() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue replyTo = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(replyTo);
Queue testQueue = session.createQueue("Test.Queue");
MessageProducer producer = session.createProducer(null);
Queue query = session.createQueue(StatisticsBroker.STATS_DESTINATION_PREFIX + testQueue.getQueueName());
Message msg = session.createMessage();
producer.send(testQueue, msg);
msg.setJMSReplyTo(replyTo);
producer.send(query, msg);
MapMessage reply = (MapMessage) consumer.receive(10 * 1000);
assertNotNull(reply);
assertTrue(reply.getMapNames().hasMoreElements());
assertTrue(reply.getJMSTimestamp() > 0);
assertEquals(Message.DEFAULT_PRIORITY, reply.getJMSPriority());
/*
for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
String name = e.nextElement().toString();
System.err.println(name+"="+reply.getObject(name));
}
*/
}
示例15: testDestinationStatsWithDot
import javax.jms.MapMessage; //导入依赖的package包/类
public void testDestinationStatsWithDot() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue replyTo = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(replyTo);
Queue testQueue = session.createQueue("Test.Queue");
MessageProducer producer = session.createProducer(null);
Queue query = session.createQueue(StatisticsBroker.STATS_DESTINATION_PREFIX + "." + testQueue.getQueueName());
Message msg = session.createMessage();
producer.send(testQueue, msg);
msg.setJMSReplyTo(replyTo);
producer.send(query, msg);
MapMessage reply = (MapMessage) consumer.receive(10 * 1000);
assertNotNull(reply);
assertTrue(reply.getMapNames().hasMoreElements());
assertTrue(reply.getJMSTimestamp() > 0);
assertEquals(Message.DEFAULT_PRIORITY, reply.getJMSPriority());
/*
for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
String name = e.nextElement().toString();
System.err.println(name+"="+reply.getObject(name));
}
*/
}