本文整理了Java中javax.jms.Message.setStringProperty()
方法的一些代码示例,展示了Message.setStringProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.setStringProperty()
方法的具体详情如下:
包路径:javax.jms.Message
类名称:Message
方法名:setStringProperty
[英]Sets a String property value with the specified name into the message.
[中]在消息中设置具有指定名称的字符串属性值。
代码示例来源:origin: spring-projects/spring-framework
/**
* Set a type id for the given payload object on the given JMS Message.
* <p>The default implementation consults the configured type id mapping and
* sets the resulting value (either a mapped id or the raw Java class name)
* into the configured type id message property.
* @param object the payload object to set a type id for
* @param message the JMS Message to set the type id on
* @throws JMSException if thrown by JMS methods
* @see #getJavaTypeForMessage(javax.jms.Message)
* @see #setTypeIdPropertyName(String)
* @see #setTypeIdMappings(java.util.Map)
*/
protected void setTypeIdOnMessage(Object object, Message message) throws JMSException {
if (this.typeIdPropertyName != null) {
String typeId = this.classIdMappings.get(object.getClass());
if (typeId == null) {
typeId = object.getClass().getName();
}
message.setStringProperty(this.typeIdPropertyName, typeId);
}
}
代码示例来源:origin: openzipkin/brave
/** This is only safe to call after {@link JmsTracing#extractAndClearMessage(Message)} */
static void addB3SingleHeader(Message message, TraceContext context) {
try {
message.setStringProperty("b3", writeB3SingleFormatWithoutParentId(context));
} catch (JMSException ignored) {
// don't crash on wonky exceptions!
}
}
代码示例来源:origin: spring-projects/spring-framework
private void assertAttemptReadDisallowedPropertyIsNotFatal(javax.jms.Message jmsMessage, String headerId)
throws JMSException {
jmsMessage.setStringProperty("foo", "bar");
Map<String, Object> headers = mapper.toHeaders(jmsMessage);
assertNull(headers.get(headerId));
assertNotNull(headers.get("foo"));
assertEquals("bar", headers.get("foo"));
}
代码示例来源:origin: apache/activemq
protected Message createMessage(int i) throws Exception {
Message answer;
if (payload != null) {
answer = session.createBytesMessage();
((BytesMessage) answer).writeBytes(payload);
} else {
if (textMessageSize > 0) {
if (messageText == null) {
messageText = readInputStream(getClass().getResourceAsStream("demo.txt"), textMessageSize, i);
}
} else if (payloadUrl != null) {
messageText = readInputStream(new URL(payloadUrl).openStream(), -1, i);
} else if (message != null) {
messageText = message;
} else {
messageText = createDefaultMessage(i);
}
answer = session.createTextMessage(messageText);
}
if ((msgGroupID != null) && (!msgGroupID.isEmpty())) {
answer.setStringProperty("JMSXGroupID", msgGroupID);
}
return answer;
}
代码示例来源:origin: apache/hive
Message msg = session.get().createTextMessage(hCatEventMessage.toString());
msg.setStringProperty(HCatConstants.HCAT_EVENT, hCatEventMessage.getEventType().toString());
msg.setStringProperty(HCatConstants.HCAT_MESSAGE_VERSION, messageFactory.getVersion());
msg.setStringProperty(HCatConstants.HCAT_MESSAGE_FORMAT, messageFactory.getMessageFormat());
MessageProducer producer = createProducer(topic);
producer.send(msg);
代码示例来源:origin: spring-projects/spring-framework
@Test
public void contentTypePropertyMappedToHeader() throws JMSException {
javax.jms.Message jmsMessage = new StubTextMessage();
jmsMessage.setStringProperty("content_type", "foo");
assertInboundHeader(jmsMessage, MessageHeaders.CONTENT_TYPE, "foo");
}
代码示例来源:origin: spring-projects/spring-framework
private void testMessageConverterIsUsed() throws JMSException {
MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(
this.listener.getClass(), "handleIt", String.class, String.class);
Message message = new StubTextMessage("foo-bar");
message.setStringProperty("my-header", "my-value");
invokeListener(endpoint, message);
assertListenerMethodInvocation("handleIt");
}
代码示例来源:origin: apache/nifi
message.setStringProperty(jmsPropName, value);
} else if (type.equalsIgnoreCase(PROP_TYPE_INTEGER)) {
message.setIntProperty(jmsPropName, Integer.parseInt(value));
代码示例来源:origin: spring-projects/spring-framework
@Test
public void parameterAnnotationWithJdkProxy() throws JMSException {
ProxyFactory pf = new ProxyFactory(sample);
listener = (JmsEndpointSampleInterface) pf.getProxy();
containerFactory.setMessageConverter(new UpperCaseMessageConverter());
MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(
JmsEndpointSampleInterface.class, "handleIt", String.class, String.class);
Message message = new StubTextMessage("foo-bar");
message.setStringProperty("my-header", "my-value");
invokeListener(endpoint, message);
assertListenerMethodInvocation("handleIt");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void parameterAnnotationWithCglibProxy() throws JMSException {
ProxyFactory pf = new ProxyFactory(sample);
pf.setProxyTargetClass(true);
listener = (JmsEndpointSampleBean) pf.getProxy();
containerFactory.setMessageConverter(new UpperCaseMessageConverter());
MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(
JmsEndpointSampleBean.class, "handleIt", String.class, String.class);
Message message = new StubTextMessage("foo-bar");
message.setStringProperty("my-header", "my-value");
invokeListener(endpoint, message);
assertListenerMethodInvocation("handleIt");
}
代码示例来源:origin: apache/activemq
public void testChangeMutableObjectInObjectMessageThenRollback() throws Exception {
ArrayList<String> list = new ArrayList<String>();
list.add("First");
Message outbound = session.createObjectMessage(list);
outbound.setStringProperty("foo", "abc");
beginTx();
producer.send(outbound);
commitTx();
LOG.info("About to consume message 1");
beginTx();
Message message = consumer.receive(5000);
List<String> body = assertReceivedObjectMessageWithListBody(message);
// now lets try mutate it
try {
message.setStringProperty("foo", "def");
fail("Cannot change properties of the object!");
} catch (JMSException e) {
LOG.info("Caught expected exception: " + e, e);
}
body.clear();
body.add("This should never be seen!");
rollbackTx();
beginTx();
message = consumer.receive(5000);
List<String> secondBody = assertReceivedObjectMessageWithListBody(message);
assertNotSame("Second call should return a different body", secondBody, body);
commitTx();
}
代码示例来源:origin: apache/activemq
@Before
public void setUp() throws Exception {
brokerService = new BrokerService();
brokerService.setPersistent(false);
brokerService.setUseJmx(true);
String connectionUri = brokerService.addConnector("tcp://localhost:0").getPublishableConnectString();
brokerService.start();
brokerService.waitUntilStarted();
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionUri);
final Connection conn = connectionFactory.createConnection();
try {
conn.start();
final Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Destination queue = session.createQueue(testQueueName);
final Message toSend = session.createMessage();
toSend.setStringProperty("foo", "bar");
final MessageProducer producer = session.createProducer(queue);
producer.send(queue, toSend);
} finally {
conn.close();
}
}
代码示例来源:origin: spring-projects/spring-integration
private void copyCorrelationIdFromRequestToReply(javax.jms.Message requestMessage, javax.jms.Message replyMessage)
throws JMSException {
if (this.correlationKey != null) {
if (this.correlationKey.equals("JMSCorrelationID")) {
replyMessage.setJMSCorrelationID(requestMessage.getJMSCorrelationID());
}
else {
String value = requestMessage.getStringProperty(this.correlationKey);
if (value != null) {
replyMessage.setStringProperty(this.correlationKey, value);
}
else if (this.logger.isWarnEnabled()) {
this.logger.warn("No property value available on request Message for correlationKey '"
+ this.correlationKey + "'");
}
}
}
else if (replyMessage.getJMSCorrelationID() == null) {
replyMessage.setJMSCorrelationID(requestMessage.getJMSMessageID());
}
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void attemptToReadDisallowedRedeliveredPropertyIsNotFatal() throws JMSException {
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public boolean getJMSRedelivered() throws JMSException {
throw new JMSException("illegal property");
}
};
jmsMessage.setStringProperty("foo", "bar");
Map<String, Object> headers = mapper.toHeaders(jmsMessage);
assertNull(headers.get(JmsHeaders.REDELIVERED));
assertNotNull(headers.get("foo"));
assertEquals("bar", headers.get("foo"));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void attemptToReadDisallowedTypePropertyIsNotFatal() throws JMSException {
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public String getJMSType() throws JMSException {
throw new JMSException("illegal property");
}
};
jmsMessage.setStringProperty("foo", "bar");
Map<String, Object> headers = mapper.toHeaders(jmsMessage);
assertNull(headers.get(JmsHeaders.TYPE));
assertNotNull(headers.get("foo"));
assertEquals("bar", headers.get("foo"));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void attemptToReadDisallowedCorrelationIdPropertyIsNotFatal() throws JMSException {
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public String getJMSCorrelationID() throws JMSException {
throw new JMSException("illegal property");
}
};
jmsMessage.setStringProperty("foo", "bar");
Map<String, Object> headers = mapper.toHeaders(jmsMessage);
assertNull(headers.get(JmsHeaders.CORRELATION_ID));
assertNotNull(headers.get("foo"));
assertEquals("bar", headers.get("foo"));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void attemptToReadDisallowedReplyToPropertyIsNotFatal() throws JMSException {
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public Destination getJMSReplyTo() throws JMSException {
throw new JMSException("illegal property");
}
};
jmsMessage.setStringProperty("foo", "bar");
Map<String, Object> headers = mapper.toHeaders(jmsMessage);
assertNull(headers.get(JmsHeaders.REPLY_TO));
assertNotNull(headers.get("foo"));
assertEquals("bar", headers.get("foo"));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void attemptToReadDisallowedMessageIdPropertyIsNotFatal() throws JMSException {
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public String getJMSMessageID() throws JMSException {
throw new JMSException("illegal property");
}
};
jmsMessage.setStringProperty("foo", "bar");
Map<String, Object> headers = mapper.toHeaders(jmsMessage);
assertNull(headers.get(JmsHeaders.MESSAGE_ID));
assertNotNull(headers.get("foo"));
assertEquals("bar", headers.get("foo"));
}
代码示例来源:origin: spring-projects/spring-integration
public void fromHeaders(MessageHeaders headers, javax.jms.Message jmsMessage) {
super.fromHeaders(headers, jmsMessage);
String messageHistory = headers.get(MessageHistory.HEADER_NAME, MessageHistory.class).toString();
try {
jmsMessage.setStringProperty("outbound_history", messageHistory);
}
catch (Exception e) {
throw new MessagingException("Problem setting JMS properties", e);
}
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testContentTypePropertyMappedToHeader() throws JMSException {
javax.jms.Message jmsMessage = new StubTextMessage();
jmsMessage.setStringProperty("content_type", "foo");
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
Map<String, Object> headers = mapper.toHeaders(jmsMessage);
Object attrib = headers.get(MessageHeaders.CONTENT_TYPE);
assertNotNull(attrib);
assertEquals("foo", attrib);
}
内容来源于网络,如有侵权,请联系作者删除!