Added 'defaultReplyDestination' to ChannelPublishingJmsMessageListener, and now throwing an Exception if there is a reply Message to send and neither a reply-to property or 'defaultReplyDestination' is available (INT-560 and INT-580).
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.jms;
|
||||
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
@@ -24,6 +25,7 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.jms.listener.SessionAwareMessageListener;
|
||||
@@ -47,6 +49,8 @@ public class ChannelPublishingJmsMessageListener implements SessionAwareMessageL
|
||||
|
||||
private volatile boolean extractReplyPayload = true;
|
||||
|
||||
private volatile Destination defaultReplyDestination;
|
||||
|
||||
private volatile JmsHeaderMapper headerMapper;
|
||||
|
||||
private final MessageChannelTemplate channelTemplate = new MessageChannelTemplate();
|
||||
@@ -84,6 +88,14 @@ public class ChannelPublishingJmsMessageListener implements SessionAwareMessageL
|
||||
this.channelTemplate.setReceiveTimeout(replyTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the default reply Destination. If a request Message does not provide
|
||||
* a 'JMSReplyTo' property, replies will be sent to this by default.
|
||||
*/
|
||||
public void setDefaultReplyDestination(Destination defaultReplyDestination) {
|
||||
this.defaultReplyDestination = defaultReplyDestination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a {@link MessageConverter} implementation to use when
|
||||
* converting between JMS Messages and Spring Integration Messages.
|
||||
@@ -152,11 +164,19 @@ public class ChannelPublishingJmsMessageListener implements SessionAwareMessageL
|
||||
else {
|
||||
Message<?> replyMessage = this.channelTemplate.sendAndReceive(requestMessage);
|
||||
if (replyMessage != null) {
|
||||
Destination destination = jmsMessage.getJMSReplyTo();
|
||||
if (destination == null) {
|
||||
destination = this.defaultReplyDestination;
|
||||
}
|
||||
if (destination == null) {
|
||||
throw new MessagingException(replyMessage, "Unable to send JMS reply. The request Message "
|
||||
+ "has no 'JMSReplyTo' property, and this listener has no 'defaultReplyDestination'.");
|
||||
}
|
||||
javax.jms.Message jmsReply = this.messageConverter.toMessage(replyMessage, session);
|
||||
if (jmsReply.getJMSCorrelationID() == null) {
|
||||
jmsReply.setJMSCorrelationID(jmsMessage.getJMSMessageID());
|
||||
}
|
||||
MessageProducer producer = session.createProducer(jmsMessage.getJMSReplyTo());
|
||||
MessageProducer producer = session.createProducer(destination);
|
||||
producer.send(jmsReply);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user