本文整理匯總了Java中javax.jms.TextMessage.setStringProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java TextMessage.setStringProperty方法的具體用法?Java TextMessage.setStringProperty怎麽用?Java TextMessage.setStringProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.TextMessage
的用法示例。
在下文中一共展示了TextMessage.setStringProperty方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: publishCiStateMessage
import javax.jms.TextMessage; //導入方法依賴的package包/類
/**
* Publish ci state message.
*
* @param event the event
*/
public void publishCiStateMessage(CiChangeStateEvent event) {
try {
TextMessage message = session.createTextMessage(gson.toJson(event));
message.setLongProperty("ciId", event.getCiId());
message.setStringProperty("type", "ci-change-state");
message.setStringProperty("ciState", event.getNewState());
producer.send(message);
logger.info("Published: ciId:" + event.getCiId());
logger.info(message.getText());
} catch (JMSException e) {
// TODO see if we can put some durability here
logger.error("caught Exception publishing",e);
}
}
示例2: publishMonitor
import javax.jms.TextMessage; //導入方法依賴的package包/類
private void publishMonitor(MonitorRequest mr) throws SensorClientException {
try {
TextMessage message = null;
message = session.createTextMessage(gson.toJson(mr));
message.setStringProperty(MSG_TYPE, MSG_TYPE_MONITOR);
message.setLongProperty(MSG_PROP_MANIFEST_ID, mr.getManifestId());
message.setLongProperty(MSG_PROP_CI_ID, mr.getCiId());
producer.send(message);
logger.info("Published: monitor for ciId:" + mr.getCiId() + "; manifestId:" + mr.getManifestId() + "; action:" + mr.getAction());
logger.debug(message.getText());
} catch (JMSException e) {
logger.error("caught Exception publishing",e);
throw new SensorClientException(e);
}
}
示例3: verstuurBijhoudingsNotificatie
import javax.jms.TextMessage; //導入方法依賴的package包/類
@Override
public void verstuurBijhoudingsNotificatie(final BijhoudingsplanNotificatieBericht notificatieBericht) {
try {
final MessageCreator messageCreator = session -> {
final TextMessage message = session.createTextMessage();
// Header voor message group mechanisme van ActiveMq
message.setStringProperty("JMSXGroupID", String.valueOf(notificatieBericht.getOntvangendePartijCode()));
message.setText(serialiseerderBijhoudingsplan.serialiseerNaarString(notificatieBericht));
return message;
};
bijhoudingsplanJmsTemplate.send(messageCreator);
} catch (final JmsException e) {
LOGGER.error("Het publiceren van het verwerk BijhoudingsplanBericht is mislukt ivm een JMS exceptie.", e);
throw e;
}
}
示例4: publishMessage
import javax.jms.TextMessage; //導入方法依賴的package包/類
/**
* Publish message.
*
* @param waitTaskName the wait task name
* @param woType the wo type
* @throws JMSException the jMS exception
*/
public void publishMessage(String processId, String execId, CmsWorkOrderSimpleBase wo, String waitTaskName, String woType) throws JMSException {
SimpleDateFormat format = new SimpleDateFormat(CmsConstants.SEARCH_TS_PATTERN);
wo.getSearchTags().put(CmsConstants.REQUEST_ENQUE_TS, format.format(new Date()));
//guarantee non empty-value for searchMap
if (version != null && StringUtils.isNotBlank(version.getGitVersion())) {
wo.getSearchTags().put(CONTROLLLER_VERSION_SEARCH_TAG, version.getGitVersion());
} else {
wo.getSearchTags().put(CONTROLLLER_VERSION_SEARCH_TAG, DEFAULT_VERSION);
}
TextMessage message = session.createTextMessage(gson.toJson(wo));
String corelationId = processId + "!" + execId + "!" + waitTaskName+"!"+getCtxtId(wo);
message.setJMSCorrelationID(corelationId);
message.setStringProperty("task_id", corelationId);
message.setStringProperty("type", woType);
String queueName;
if ("true".equals(System.getProperty(USE_SHARED_FLAG))) {
queueName = SHARED_QUEUE;
} else {
queueName = (wo.getCloud().getCiAttributes().get("location").replaceAll("/", ".") + QUEUE_SUFFIX).substring(
1);
}
bindingQueusMap.computeIfAbsent(queueName, k -> {
try {
return newMessageProducer(k);
} catch (JMSException e) {
throw new RuntimeException(e);
}
}).send(message);
if (logger.isDebugEnabled()) {
logger.debug("Published: " + message.getText());
}
logger.info("Posted message with id "+ corelationId +" to q: "+queueName);
}
示例5: createTextMessage
import javax.jms.TextMessage; //導入方法依賴的package包/類
protected TextMessage createTextMessage(MessageData data) throws JMSException {
TextMessage message = session.createTextMessage(data.getPayload());
Map<String, String> headers = data.getHeaders();
if (headers != null) {
for (String key : headers.keySet()) {
message.setStringProperty(key, headers.get(key));
}
}
return message;
}
示例6: createTextMessage
import javax.jms.TextMessage; //導入方法依賴的package包/類
protected TextMessage createTextMessage(MessageData data) throws JMSException {
TextMessage message = session.createTextMessage(data.getPayload());
Map<String, String> headers = data.getHeaders();
for (String key : headers.keySet()) {
message.setStringProperty(key, headers.get(key));
}
return message;
}
示例7: xmitData
import javax.jms.TextMessage; //導入方法依賴的package包/類
@Override
public void xmitData(String data) {
try {
if(mXmitDisable == false){
TextMessage message = session.createTextMessage(data);
message.setStringProperty("JMSXGroupID", "Default");
message.setStringProperty("JMS_SQS_DeduplicationId", deDuplicationId+(seqNum++));
producer.send(message);
}
} catch (JMSException e) {
System.err.println( "Failed sending message: " + e.getMessage() );
e.printStackTrace();
}
}
示例8: setStringProperty
import javax.jms.TextMessage; //導入方法依賴的package包/類
private static void setStringProperty(TextMessage message, String header, String value) throws JMSException {
LOG.debug("Setting header [{}] value [{}]", header, value);
message.setStringProperty(header, value);
}
示例9: testPositiveJMSSelectorConsumerProducer
import javax.jms.TextMessage; //導入方法依賴的package包/類
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"})
@Test
public void testPositiveJMSSelectorConsumerProducer(String port,
String adminUsername,
String adminPassword,
String brokerHostname) throws NamingException, JMSException {
String queueName = "testPositiveJMSSelectorConsumerProducer";
InitialContext initialContext = ClientHelper
.getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
.withTopic(queueName)
.build();
TopicConnectionFactory connectionFactory
= (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
TopicConnection connection = connectionFactory.createTopicConnection();
connection.start();
TopicSession subscriberSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) initialContext.lookup(queueName);
// Subscribe with a selector
String propertyName = "MyProperty";
String propertyValue = "propertyValue";
String jmsPropertySelector = propertyName + " = '" + propertyValue + "'";
TopicSubscriber consumer = subscriberSession.createSubscriber(topic, jmsPropertySelector, false);
// publish messages with property
TopicSession producerSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
TopicPublisher producer = producerSession.createPublisher(topic);
int numberOfMessages = 100;
for (int i = 0; i < numberOfMessages; i++) {
TextMessage textMessage = producerSession.createTextMessage("Test message " + i);
textMessage.setStringProperty(propertyName, propertyValue);
producer.send(textMessage);
}
// consume messages
for (int i = 0; i < numberOfMessages; i++) {
Message message = consumer.receive(1000);
Assert.assertNotNull(message, "Message #" + i + " was not received");
}
producerSession.close();
connection.close();
}
示例10: testNegativeJMSSelectorConsumerProducer
import javax.jms.TextMessage; //導入方法依賴的package包/類
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"})
@Test
public void testNegativeJMSSelectorConsumerProducer(String port,
String adminUsername,
String adminPassword,
String brokerHostname) throws NamingException, JMSException {
String queueName = "testNegativeJMSSelectorConsumerProducer";
InitialContext initialContext = ClientHelper
.getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
.withTopic(queueName)
.build();
TopicConnectionFactory connectionFactory
= (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
TopicConnection connection = connectionFactory.createTopicConnection();
connection.start();
TopicSession subscriberSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) initialContext.lookup(queueName);
// Subscribe with a selector
String propertyName = "MyProperty";
String propertyValue = "propertyValue";
String jmsPropertySelector = propertyName + " = '" + propertyValue + "'";
TopicSubscriber consumer = subscriberSession.createSubscriber(topic, jmsPropertySelector, false);
// publish messages with property
TopicSession producerSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
TopicPublisher producer = producerSession.createPublisher(topic);
// Send messages with a different property value
int numberOfMessages = 100;
for (int i = 0; i < numberOfMessages; i++) {
TextMessage textMessage = producerSession.createTextMessage("Test message " + i);
textMessage.setStringProperty(propertyName, propertyValue + "-1");
producer.send(textMessage);
}
// consume messages
Message message = consumer.receive(100);
Assert.assertNull(message, "Message received. Shouldn't receive any messages.");
producerSession.close();
connection.close();
}