當前位置: 首頁>>代碼示例>>Java>>正文


Java Session.createObjectMessage方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:18,代碼來源:TriggerQueueServiceBean.java

示例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;
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:26,代碼來源:JmsClient.java

示例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");
		}
	}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:28,代碼來源:InvokeMessageConverter.java

示例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");
	}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:22,代碼來源:Publisher.java

示例5: toMessage

import javax.jms.Session; //導入方法依賴的package包/類
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
	return session.createObjectMessage((Serializable) object);
}
 
開發者ID:duanyaxin,項目名稱:springboot-smart,代碼行數:5,代碼來源:WXMessageConverter.java


注:本文中的javax.jms.Session.createObjectMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。