本文整理匯總了Java中javax.jms.Session.createMapMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java Session.createMapMessage方法的具體用法?Java Session.createMapMessage怎麽用?Java Session.createMapMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.Session
的用法示例。
在下文中一共展示了Session.createMapMessage方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doPublish
import javax.jms.Session; //導入方法依賴的package包/類
protected void doPublish(Event event) throws EdsException {
Connection conn = null;
Session session = null;
MessageProducer messageProducer = null;
try {
LOG.debug("eds pub 3 mq in -[event:" + event + "]");
conn = connectionFactory.createConnection();
// 設置非事務,客戶端確認方式
session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MapMessage mapMessage = session.createMapMessage();
mapMessage = EventConverter.convertToMessage(mapMessage, event);
Destination dest = getDestination(event.getName(), session);
messageProducer = session.createProducer(dest);
messageProducer.send(mapMessage);
// commit session if necessary
if (session.getTransacted()) {
session.commit();
}
LOG.debug("eds pub 4 mq ok -[conn:" + conn + ",session:" + session + ",event:" + event + "]");
}catch(JMSException e){
throw new EdsException("eds client activemq doPublish exception ", e);
}finally {
releaseSession(session);
releaseMessageProducer(messageProducer);
releaseConnection(conn, false);
}
}
示例2: toMessage
import javax.jms.Session; //導入方法依賴的package包/類
@Override
public Message toMessage(Object object, Session session) throws JMSException,
MessageConversionException {
if(object instanceof Event){
MapMessage mapMessage = session.createMapMessage();
// Event ev = new Event();
return EventConverter.convertToMessage(mapMessage, (Event)object);
}
throw new EdsException("eds event to message conversion exception : " + ToStringBuilder.reflectionToString(object));
}
示例3: toMessage
import javax.jms.Session; //導入方法依賴的package包/類
public Message toMessage(Object obj, Session session) throws JMSException, MessageConversionException {
LOGGER.info("往mq插入message, message內容:" + obj);
JSONObject jsonRoot = new JSONObject();
JSONObject jsonObj = new JSONObject();
jsonObj.put("topic", "MSG_PUSH");
jsonObj.put("body", obj);
jsonObj.put("isFromJava", true);
jsonRoot.put("value", jsonObj.toJSONString());
Message message = session.createMapMessage();
message.setObjectProperty("obj", jsonRoot.toJSONString());
return message;
}