本文整理匯總了Java中javax.jms.Session.createObjectMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java Session.createObjectMessage方法的具體用法?Java Session.createObjectMessage怎麽用?Java Session.createObjectMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.Session
的用法示例。
在下文中一共展示了Session.createObjectMessage方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendObjectMsgSingleSession
import javax.jms.Session; //導入方法依賴的package包/類
private void sendObjectMsgSingleSession(List<? extends Serializable> objectsToSend) throws JMSException {
Session session = null;
Connection conn = null;
try {
conn = qFactory.createConnection();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
for (Serializable objectToSend : objectsToSend) {
ObjectMessage msg = session.createObjectMessage();
msg.setObject(objectToSend);
producer.send(msg);
}
} finally {
closeSession(session);
closeConnection(conn);
}
}
示例2: createMessage
import javax.jms.Session; //導入方法依賴的package包/類
public Message createMessage(Object messageObject) throws JMSException {
Connection connection = null;
Message result = null;
try {
connection = startConnection();
Session session = null;
try {
session = connection.createSession(isTransacted, Session.AUTO_ACKNOWLEDGE);
if (messageObject == null) {
result = session.createMessage();
} else {
if (messageObject instanceof String) {
result = session.createTextMessage((String) messageObject);
} else {
result = session.createObjectMessage((Serializable) messageObject);
}
}
} finally {
if (session != null) session.close();
}
} finally {
safeCloseConnection(connection);
}
return result;
}
示例3: toMessage
import javax.jms.Session; //導入方法依賴的package包/類
public Message toMessage(Object obj, Session session) throws JMSException,
MessageConversionException {
if (obj instanceof InvokeMessage) {
ActiveMQObjectMessage objMsg = (ActiveMQObjectMessage) session
.createObjectMessage();
long delay=5*1000;
System.out.println("延時:"+delay/1000+"秒");
System.out.println("msgId:"+objMsg.getJMSMessageID());
objMsg.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
// objMsg.setExpiration(2000);
Map<String, byte[]> map = new HashMap<String, byte[]>();
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
map.put("InvokeMessage", bos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
objMsg.setObjectProperty("Map", map);
return objMsg;
} else {
throw new JMSException("Object:[" + obj + "] is not InvokeMessage");
}
}
示例4: createConnectionAndSendMessage
import javax.jms.Session; //導入方法依賴的package包/類
public void createConnectionAndSendMessage(String ipAddress) throws JMSException {
Connection connection = connectionFactory.createConnection();
connection.start();
Session topicSession = connection.createSession(false, AUTO_ACKNOWLEDGE);
MessageProducer producer = topicSession.createProducer(topic);
producer.setDeliveryMode(PERSISTENT);
ObjectMessage message = topicSession.createObjectMessage();
BUSStop busStop = new BUSStop();
busStop.setName("Rome");
message.setStringProperty("s_id", "Sample");
message.setObject((Serializable) busStop);
producer.send(message);
logger.info("message sent successfully");
}
示例5: toMessage
import javax.jms.Session; //導入方法依賴的package包/類
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
return session.createObjectMessage((Serializable) object);
}