本文整理匯總了Java中javax.jms.ObjectMessage.setStringProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectMessage.setStringProperty方法的具體用法?Java ObjectMessage.setStringProperty怎麽用?Java ObjectMessage.setStringProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.ObjectMessage
的用法示例。
在下文中一共展示了ObjectMessage.setStringProperty方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: publish
import javax.jms.ObjectMessage; //導入方法依賴的package包/類
private static void publish(String destination, Serializable object, String contentType) throws Exception {
Connection conn = createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination dest = session.createQueue(destination);
try {
assertNotNull("Destination was null", dest);
MessageProducer producer = session.createProducer(dest);
ObjectMessage message = session.createObjectMessage();
if (contentType != null) {
message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
}
message.setObject(object);
producer.send(message);
} finally {
conn.close();
}
}
示例2: publish
import javax.jms.ObjectMessage; //導入方法依賴的package包/類
public static void publish(String dest, Serializable object, String contentType) throws Exception {
Connection conn = connectionFactory.createConnection();
try {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = createDestination(dest);
MessageProducer producer = session.createProducer(destination);
ObjectMessage message = session.createObjectMessage();
if (contentType != null) {
message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
}
message.setObject(object);
producer.send(message);
} finally {
conn.close();
}
}
示例3: publish
import javax.jms.ObjectMessage; //導入方法依賴的package包/類
public static void publish(String dest, Serializable object, String contentType, String tag) throws Exception {
Connection conn = connectionFactory.createConnection();
try {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = createDestination(dest);
MessageProducer producer = session.createProducer(destination);
ObjectMessage message = session.createObjectMessage();
if (contentType != null) {
message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
}
if (tag != null) {
message.setStringProperty("MyTag", tag);
}
message.setObject(object);
producer.send(message);
} finally {
conn.close();
}
}
示例4: publish
import javax.jms.ObjectMessage; //導入方法依賴的package包/類
public static void publish(String destination, Serializable object, String contentType) throws Exception {
BindingRegistry reg = server.getRegistry();
ConnectionFactory factory = (ConnectionFactory) reg.lookup("ConnectionFactory");
Connection conn = factory.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination dest = session.createQueue(destination);
try {
Assert.assertNotNull("Destination was null", dest);
MessageProducer producer = session.createProducer(dest);
ObjectMessage message = session.createObjectMessage();
if (contentType != null) {
message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
}
message.setObject(object);
producer.send(message);
} finally {
conn.close();
}
}
示例5: jmsSendMessage
import javax.jms.ObjectMessage; //導入方法依賴的package包/類
private void jmsSendMessage(Serializable value, String destName, boolean isQueue) throws JMSException {
ConnectionFactory factory = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
String jmsDest;
if (isQueue) {
jmsDest = QUEUE_QUALIFIED_PREFIX + destName;
} else {
jmsDest = TOPIC_QUALIFIED_PREFIX + destName;
}
Destination destination = ActiveMQDestination.fromPrefixedName(jmsDest);
Connection conn = factory.createConnection();
try {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
ObjectMessage message = session.createObjectMessage();
message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, "application/xml");
message.setObject(value);
producer.send(message);
} finally {
conn.close();
}
}
示例6: sendMessage
import javax.jms.ObjectMessage; //導入方法依賴的package包/類
private void sendMessage(String command, Serializable obj, String rashodCode) throws JMSException {
ObjectMessage addMessage = session.createObjectMessage();
addMessage.setStringProperty("operation", command);
addMessage.setStringProperty("rashodCode", rashodCode);
addMessage.setObject(obj);
producer.send(addMessage);
}
示例7: sendCallMessage
import javax.jms.ObjectMessage; //導入方法依賴的package包/類
public void sendCallMessage(Serializable object, String id, HostsLocal host/*String oui, String sn*/) throws JMSException {
ObjectMessage msg = queuesession.createObjectMessage();
msg.setJMSMessageID(id);
msg.setJMSExpiration(3600 * 1000);
msg.setObject(object);
/*
msg.setStringProperty("OUI", oui);
msg.setStringProperty("SN", sn);
*/
msg.setStringProperty("HWID", host.getHwid().toString());
msg.setStringProperty("SN", host.getSerialno());
producer.send(queue, msg);
}
示例8: sendMessage
import javax.jms.ObjectMessage; //導入方法依賴的package包/類
public void sendMessage(CustomerOrder customerOrder) {
ObjectMessage msgObj = context.createObjectMessage();
try {
msgObj.setObject(customerOrder);
msgObj.setStringProperty("OrderID", String.valueOf(customerOrder.getId()));
context.createProducer().send(queue, msgObj);
} catch (JMSException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
示例9: sendObjectMessageAndSetTime
import javax.jms.ObjectMessage; //導入方法依賴的package包/類
/**
* 定時發送
* @param session
* @param producer
* @throws Exception
*/
public static void sendObjectMessageAndSetTime(Session session, MessageProducer producer) throws Exception {
for (int i = 1; i <= SEND_NUMBER; i++) {
ObjectMessage objMsg = session.createObjectMessage();
// 類型
objMsg.setStringProperty("type", MESSAGE_TYPE);
// push發送配置
PushConfig config = new PushConfig();
//config.setMobile(""); // 按手機號
// config.setUuid(""); // uuid 按設備唯一標示
config.setUid(662281); // 按uid
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
config.setPush_time(sdf.parse("2016-01-28 17:01:00")); // 設置定期推送時間
//config.setExpiration_interval(86400L); // 消息過期的相對時間,從調用 API 的時間開始算起,單位是「秒」
//config.setExpiration_time(sdf.parse("2016-01-28 14:35:00"));// 消息過期的絕對日期時間
} catch (Exception e) {
e.printStackTrace();
}
PushMessage msg = new PushMessage();
msg.setTitle("push title");
msg.setAlert("通過mq發送"); // 如果隻是通知消息,設置alert即可
//msg.setUrl("push url");
config.setPushMessage(msg);
objMsg.setObject(config);
producer.send(objMsg);
}
}
示例10: sendObjectMessage
import javax.jms.ObjectMessage; //導入方法依賴的package包/類
/**
* 發送 PushMessage 對象
* @param session
* @param producer
* @throws Exception
*/
public static void sendObjectMessage(Session session, MessageProducer producer) throws Exception {
for (int i = 1; i <= SEND_NUMBER; i++) {
ObjectMessage objMsg = session.createObjectMessage();
// 類型
objMsg.setStringProperty("type", MESSAGE_TYPE);
// push發送配置
PushConfig config = new PushConfig();
//config.setMobile(""); // 按手機號
// config.setUuid(""); // uuid 按設備唯一標示
config.setUid(662281); // 按uid
/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
config.setPush_time(sdf.parse("2016-01-27 14:57:00")); // 設置定期推送時間
//config.setExpiration_interval(86400L); // 消息過期的相對時間,從調用 API 的時間開始算起,單位是「秒」
config.setExpiration_time(sdf.parse("2016-01-28 14:35:00"));// 消息過期的絕對日期時間
} catch (Exception e) {
e.printStackTrace();
}*/
PushMessage msg = new PushMessage();
//msg.setTitle("push title");
msg.setAlert("通過mq發送"); // 如果隻是通知消息,設置alert即可
//msg.setUrl("push url");
config.setPushMessage(msg);
objMsg.setObject(config);
producer.send(objMsg);
}
}
示例11: createConnectionAndSendMessage
import javax.jms.ObjectMessage; //導入方法依賴的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");
}
示例12: testSendEmptyMessages
import javax.jms.ObjectMessage; //導入方法依賴的package包/類
@Test
public void testSendEmptyMessages() throws Exception {
Queue dest = new ActiveMQQueue(queueName);
QueueSession defaultQueueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender defaultSender = defaultQueueSession.createSender(dest);
defaultSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
connection.start();
Message msg = defaultQueueSession.createMessage();
msg.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(msg);
QueueReceiver queueReceiver = defaultQueueSession.createReceiver(dest);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
//bytes
BytesMessage bytesMessage = defaultQueueSession.createBytesMessage();
bytesMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(bytesMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
//map
MapMessage mapMessage = defaultQueueSession.createMapMessage();
mapMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(mapMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
//object
ObjectMessage objMessage = defaultQueueSession.createObjectMessage();
objMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(objMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
//stream
StreamMessage streamMessage = defaultQueueSession.createStreamMessage();
streamMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(streamMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
//text
TextMessage textMessage = defaultQueueSession.createTextMessage();
textMessage.setStringProperty("testName", "testSendEmptyMessages");
defaultSender.send(textMessage);
assertNotNull("Didn't receive message", queueReceiver.receive(1000));
}