DefaultMessageEndpoint now sets the reply Message's correlationId to the original Message's id by default (INT-130).

This commit is contained in:
Mark Fisher
2008-02-26 05:09:32 +00:00
parent 07c9c376df
commit 17def0e904
2 changed files with 39 additions and 0 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.integration.endpoint;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -521,6 +522,41 @@ public class DefaultMessageEndpointTests {
assertEquals(message2, ((MessageDeliveryException) error).getUndeliveredMessage());
}
@Test
public void testCorrelationId() {
SimpleChannel replyChannel = new SimpleChannel(1);
DefaultMessageEndpoint endpoint = new DefaultMessageEndpoint(new MessageHandler() {
public Message<?> handle(Message<?> message) {
return message;
}
});
endpoint.start();
Message<?> message = new StringMessage("test");
message.getHeader().setReturnAddress(replyChannel);
endpoint.handle(message);
Message<?> reply = replyChannel.receive(500);
assertEquals(message.getId(), reply.getHeader().getCorrelationId());
}
@Test
public void testCorrelationIdSetByHandlerTakesPrecedence() {
SimpleChannel replyChannel = new SimpleChannel(1);
DefaultMessageEndpoint endpoint = new DefaultMessageEndpoint(new MessageHandler() {
public Message<?> handle(Message<?> message) {
message.getHeader().setCorrelationId("ABC-123");
return message;
}
});
endpoint.start();
Message<?> message = new StringMessage("test");
message.getHeader().setReturnAddress(replyChannel);
endpoint.handle(message);
Message<?> reply = replyChannel.receive(500);
Object correlationId = reply.getHeader().getCorrelationId();
assertFalse(message.getId().equals(correlationId));
assertEquals("ABC-123", correlationId);
}
private static ExecutorService createExecutor() {
return new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());