Added the 'replyChannel' property to MessageHeader. It takes precedence over the 'replyChannelName' when DefaultMessageEndpoint resolves the channel for reply Messages.

This commit is contained in:
Mark Fisher
2008-01-31 23:14:47 +00:00
parent 1f5e7b5756
commit 753a67b8a4
3 changed files with 68 additions and 6 deletions

View File

@@ -228,10 +228,15 @@ public class DefaultMessageEndpoint implements MessageEndpoint, ChannelRegistryA
return null;
}
private MessageChannel resolveReplyChannel(String replyChannelName) {
private MessageChannel resolveReplyChannel(MessageHeader originalMessageHeader) {
MessageChannel replyChannel = originalMessageHeader.getReplyChannel();
if (replyChannel != null) {
return replyChannel;
}
if (this.channelRegistry == null) {
return null;
}
String replyChannelName = originalMessageHeader.getReplyChannelName();
if (StringUtils.hasText(replyChannelName)) {
return this.channelRegistry.lookupChannel(replyChannelName);
}
@@ -248,12 +253,11 @@ public class DefaultMessageEndpoint implements MessageEndpoint, ChannelRegistryA
if (replyMessage == null) {
return;
}
String replyChannelName = originalMessageHeader.getReplyChannelName();
MessageChannel replyChannel = resolveReplyChannel(replyChannelName);
MessageChannel replyChannel = resolveReplyChannel(originalMessageHeader);
if (replyChannel == null) {
throw new MessageHandlingException("Unable to determine reply channel for message. "
+ "Provide a 'replyChannelName' in the message header or a 'defaultOutputChannelName' "
+ "on the message endpoint.");
throw new MessageHandlingException("Unable to determine reply channel for message. " +
"Provide a 'replyChannel' or 'replyChannelName' in the message header " +
"or a 'defaultOutputChannelName' on the message endpoint.");
}
replyChannel.send(replyMessage);
}

View File

@@ -23,6 +23,8 @@ import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.integration.channel.MessageChannel;
/**
* A holder for Message metadata. This includes information that may be used by
* the messaging system (such as <i>correlationId</i>) as well as information
@@ -40,6 +42,8 @@ public class MessageHeader {
private Object correlationId;
private MessageChannel replyChannel;
private String replyChannelName;
private int sequenceNumber = 1;
@@ -82,6 +86,14 @@ public class MessageHeader {
this.correlationId = correlationId;
}
public MessageChannel getReplyChannel() {
return this.replyChannel;
}
public void setReplyChannel(MessageChannel replyChannel) {
this.replyChannel = replyChannel;
}
public String getReplyChannelName() {
return this.replyChannelName;
}