本文整理了Java中javax.jms.Message.getJMSReplyTo()
方法的一些代码示例,展示了Message.getJMSReplyTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getJMSReplyTo()
方法的具体详情如下:
包路径:javax.jms.Message
类名称:Message
方法名:getJMSReplyTo
[英]Gets the Destination object to which a reply to this message should be sent.
[中]获取应向其发送对此消息的答复的目标对象。
代码示例来源:origin: spring-projects/spring-framework
/**
* Send the given RemoteInvocationResult as a JMS message to the originator.
* @param requestMessage current request message
* @param session the JMS Session to use
* @param result the RemoteInvocationResult object
* @throws javax.jms.JMSException if thrown by trying to send the message
*/
protected void writeRemoteInvocationResult(
Message requestMessage, Session session, RemoteInvocationResult result) throws JMSException {
Message response = createResponseMessage(requestMessage, session, result);
MessageProducer producer = session.createProducer(requestMessage.getJMSReplyTo());
try {
producer.send(response);
}
finally {
JmsUtils.closeMessageProducer(producer);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine a response destination for the given message.
* <p>The default implementation first checks the JMS Reply-To
* {@link Destination} of the supplied request; if that is not {@code null}
* it is returned; if it is {@code null}, then the configured
* {@link #resolveDefaultResponseDestination default response destination}
* is returned; if this too is {@code null}, then an
* {@link javax.jms.InvalidDestinationException} is thrown.
* @param request the original incoming JMS message
* @param response the outgoing JMS message about to be sent
* @param session the JMS Session to operate on
* @return the response destination (never {@code null})
* @throws JMSException if thrown by JMS API methods
* @throws javax.jms.InvalidDestinationException if no {@link Destination} can be determined
* @see #setDefaultResponseDestination
* @see javax.jms.Message#getJMSReplyTo()
*/
protected Destination getResponseDestination(Message request, Message response, Session session)
throws JMSException {
Destination replyTo = request.getJMSReplyTo();
if (replyTo == null) {
replyTo = resolveDefaultResponseDestination(session);
if (replyTo == null) {
throw new InvalidDestinationException("Cannot determine response destination: " +
"Request message does not contain reply-to destination, and no default response destination set.");
}
}
return replyTo;
}
代码示例来源:origin: log4j/log4j
sbuf.append(m.getJMSReplyTo());
代码示例来源:origin: spring-projects/spring-framework
Destination replyTo = jmsMessage.getJMSReplyTo();
if (replyTo != null) {
headers.put(JmsHeaders.REPLY_TO, replyTo);
代码示例来源:origin: apache/nifi
private Map<String, String> extractMessageHeaders(final Message message) throws JMSException {
final Map<String, String> messageHeaders = new HashMap<>();
messageHeaders.put(JmsHeaders.DELIVERY_MODE, String.valueOf(message.getJMSDeliveryMode()));
messageHeaders.put(JmsHeaders.EXPIRATION, String.valueOf(message.getJMSExpiration()));
messageHeaders.put(JmsHeaders.PRIORITY, String.valueOf(message.getJMSPriority()));
messageHeaders.put(JmsHeaders.REDELIVERED, String.valueOf(message.getJMSRedelivered()));
messageHeaders.put(JmsHeaders.TIMESTAMP, String.valueOf(message.getJMSTimestamp()));
messageHeaders.put(JmsHeaders.CORRELATION_ID, message.getJMSCorrelationID());
messageHeaders.put(JmsHeaders.MESSAGE_ID, message.getJMSMessageID());
messageHeaders.put(JmsHeaders.TYPE, message.getJMSType());
String replyToDestinationName = this.retrieveDestinationName(message.getJMSReplyTo(), JmsHeaders.REPLY_TO);
if (replyToDestinationName != null) {
messageHeaders.put(JmsHeaders.REPLY_TO, replyToDestinationName);
}
String destinationName = this.retrieveDestinationName(message.getJMSDestination(), JmsHeaders.DESTINATION);
if (destinationName != null) {
messageHeaders.put(JmsHeaders.DESTINATION, destinationName);
}
return messageHeaders;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void jmsReplyToMappedFromHeader() throws JMSException {
Destination replyTo = new Destination() {};
Message<String> message = initBuilder()
.setHeader(JmsHeaders.REPLY_TO, replyTo).build();
javax.jms.Message jmsMessage = new StubTextMessage();
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNotNull(jmsMessage.getJMSReplyTo());
assertSame(replyTo, jmsMessage.getJMSReplyTo());
}
代码示例来源:origin: apache/nifi
attributes.put(ATTRIBUTE_PREFIX + JMS_MESSAGE_ID, message.getJMSMessageID());
if (message.getJMSReplyTo() != null) {
attributes.put(ATTRIBUTE_PREFIX + JMS_REPLY_TO, message.getJMSReplyTo().toString());
代码示例来源:origin: spring-projects/spring-framework
@Override
protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException {
Session mockExporterSession = mock(Session.class);
ResponseStoringProducer mockProducer = new ResponseStoringProducer();
given(mockExporterSession.createProducer(requestMessage.getJMSReplyTo())).willReturn(mockProducer);
exporter.onMessage(requestMessage, mockExporterSession);
assertTrue(mockProducer.closed);
return mockProducer.response;
}
};
代码示例来源:origin: spring-projects/spring-framework
@Test
public void JmsReplyToIgnoredIfIncorrectType() throws JMSException {
Message<String> message = initBuilder()
.setHeader(JmsHeaders.REPLY_TO, "not-a-destination").build();
javax.jms.Message jmsMessage = new StubTextMessage();
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSReplyTo());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void attemptToWriteDisallowedReplyToPropertyIsNotFatal() throws JMSException {
Message<String> message = initBuilder()
.setHeader(JmsHeaders.REPLY_TO, new Destination() {})
.setHeader("foo", "bar")
.build();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public void setJMSReplyTo(Destination replyTo) throws JMSException {
throw new JMSException("illegal property");
}
};
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSReplyTo());
assertNotNull(jmsMessage.getStringProperty("foo"));
assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
代码示例来源:origin: apache/activemq
if (jmsMessageConvertor != null) {
if (doHandleReplyTo) {
Destination replyTo = message.getJMSReplyTo();
if (replyTo != null) {
converted = jmsMessageConvertor.convert(message, processReplyToDestination(replyTo));
代码示例来源:origin: wildfly/wildfly
setJMSReplyTo(foreign.getJMSReplyTo());
setJMSDestination(foreign.getJMSDestination());
setJMSDeliveryMode(foreign.getJMSDeliveryMode());
代码示例来源:origin: spring-projects/spring-framework
@Test
public void buildMessageWithStandardMessage() throws JMSException {
Destination replyTo = new Destination() {};
Message<String> result = MessageBuilder.withPayload("Response")
.setHeader("foo", "bar")
.setHeader(JmsHeaders.TYPE, "msg_type")
.setHeader(JmsHeaders.REPLY_TO, replyTo)
.build();
Session session = mock(Session.class);
given(session.createTextMessage("Response")).willReturn(new StubTextMessage("Response"));
MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
javax.jms.Message replyMessage = listener.buildMessage(session, result);
verify(session).createTextMessage("Response");
assertNotNull("reply should never be null", replyMessage);
assertEquals("Response", ((TextMessage) replyMessage).getText());
assertEquals("custom header not copied", "bar", replyMessage.getStringProperty("foo"));
assertEquals("type header not copied", "msg_type", replyMessage.getJMSType());
assertEquals("replyTo header not copied", replyTo, replyMessage.getJMSReplyTo());
}
代码示例来源:origin: apache/activemq
/**
* Copies the standard JMS and user defined properties from the givem
* message to the specified message
*
* @param fromMessage the message to take the properties from
* @param toMessage the message to add the properties to
* @throws JMSException
*/
public static void copyProperties(Message fromMessage, Message toMessage) throws JMSException {
toMessage.setJMSMessageID(fromMessage.getJMSMessageID());
toMessage.setJMSCorrelationID(fromMessage.getJMSCorrelationID());
toMessage.setJMSReplyTo(transformDestination(fromMessage.getJMSReplyTo()));
toMessage.setJMSDestination(transformDestination(fromMessage.getJMSDestination()));
toMessage.setJMSDeliveryMode(fromMessage.getJMSDeliveryMode());
toMessage.setJMSRedelivered(fromMessage.getJMSRedelivered());
toMessage.setJMSType(fromMessage.getJMSType());
toMessage.setJMSExpiration(fromMessage.getJMSExpiration());
toMessage.setJMSPriority(fromMessage.getJMSPriority());
toMessage.setJMSTimestamp(fromMessage.getJMSTimestamp());
Enumeration propertyNames = fromMessage.getPropertyNames();
while (propertyNames.hasMoreElements()) {
String name = propertyNames.nextElement().toString();
Object obj = fromMessage.getObjectProperty(name);
toMessage.setObjectProperty(name, obj);
}
}
}
代码示例来源:origin: spring-projects/spring-integration
public void onMessage(javax.jms.Message request, Session session) throws JMSException {
String text = "priority=" + request.getJMSPriority();
TextMessage reply = session.createTextMessage(text);
MessageProducer producer = session.createProducer(request.getJMSReplyTo());
reply.setJMSCorrelationID(request.getJMSMessageID());
producer.send(reply);
}
}
代码示例来源:origin: spring-projects/spring-integration
private void receiveAndSend(JmsTemplate template) {
javax.jms.Message request = template.receive(requestQueue7);
final javax.jms.Message jmsReply = request;
try {
template.send(request.getJMSReplyTo(), session -> jmsReply);
}
catch (JmsException | JMSException e) {
}
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testJmsReplyToMappedFromHeader() throws JMSException {
Destination replyTo = new Destination() {
};
Message<String> message = MessageBuilder.withPayload("test")
.setHeader(JmsHeaders.REPLY_TO, replyTo).build();
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage();
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNotNull(jmsMessage.getJMSReplyTo());
assertSame(replyTo, jmsMessage.getJMSReplyTo());
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testJmsReplyToIgnoredIfIncorrectType() throws JMSException {
Message<String> message = MessageBuilder.withPayload("test")
.setHeader(JmsHeaders.REPLY_TO, "not-a-destination").build();
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage();
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSReplyTo());
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void attemptToWriteDisallowedReplyToPropertyIsNotFatal() throws JMSException {
Message<String> message = MessageBuilder.withPayload("test")
.setHeader(JmsHeaders.REPLY_TO, new StubDestination())
.setHeader("foo", "bar")
.build();
DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
javax.jms.Message jmsMessage = new StubTextMessage() {
@Override
public void setJMSReplyTo(Destination replyTo) throws JMSException {
throw new JMSException("illegal property");
}
};
mapper.fromHeaders(message.getHeaders(), jmsMessage);
assertNull(jmsMessage.getJMSReplyTo());
assertNotNull(jmsMessage.getStringProperty("foo"));
assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testWithReply() throws Exception {
QueueChannel replies = new QueueChannel();
this.gateway1.setOutputChannel(replies);
this.gateway1.start();
this.gateway1.handleMessage(MessageBuilder.withPayload("foo")
.setHeader(JmsHeaders.CORRELATION_ID, "baz")// make sure it's restored in case we're from an upstream gw
.build());
JmsTemplate template = new JmsTemplate(this.ccf);
template.setReceiveTimeout(10000);
final Message received = template.receive("asyncTest1");
assertNotNull(received);
template.send(received.getJMSReplyTo(), (MessageCreator) session -> {
TextMessage textMessage = session.createTextMessage("bar");
textMessage.setJMSCorrelationID(received.getJMSCorrelationID());
return textMessage;
});
org.springframework.messaging.Message<?> reply = replies.receive(10000);
assertNotNull(reply);
assertEquals("bar", reply.getPayload());
assertEquals("baz", reply.getHeaders().get(JmsHeaders.CORRELATION_ID));
this.gateway1.stop();
}
内容来源于网络,如有侵权,请联系作者删除!