Showing a workaround to make message serializable
this issue is there in core of Spring Framework (https://jira.spring.io/browse/SPR-15262) but this tests shows how to apply a workaround to get ridd of that problem until we bump up version of SF. related to https://github.com/spring-cloud/spring-cloud-sleuth/issues/520 and https://github.com/spring-cloud/spring-cloud-sleuth/issues/523 SO - http://stackoverflow.com/questions/42277170/messagedeliveryexception-thrown-when-using-amqp-backed-channel-with-brixton-sr7 fixes #520
This commit is contained in:
@@ -42,11 +42,16 @@ import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.core.MessagingTemplate;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.messaging.support.ChannelInterceptorAdapter;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.messaging.support.MessageHeaderAccessor;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
@@ -314,6 +319,28 @@ public class TraceChannelInterceptorTests implements MessageHandler {
|
||||
then(TestSpanContextHolder.getCurrentSpan()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeMutableHeaders() throws Exception {
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("foo", "bar");
|
||||
Message<?> message = new GenericMessage<>("test", headers);
|
||||
ChannelInterceptor immutableMessageInterceptor = new ChannelInterceptorAdapter() {
|
||||
@Override
|
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
MessageHeaderAccessor headers = MessageHeaderAccessor.getMutableAccessor(message);
|
||||
return new GenericMessage<Object>(message.getPayload(), headers.toMessageHeaders());
|
||||
}
|
||||
};
|
||||
this.tracedChannel.addInterceptor(immutableMessageInterceptor);
|
||||
|
||||
this.tracedChannel.send(message);
|
||||
|
||||
Message<?> output = (Message<?>) SerializationUtils.deserialize(SerializationUtils.serialize(this.message));
|
||||
then(output.getPayload()).isEqualTo("test");
|
||||
then(output.getHeaders().get("foo")).isEqualTo("bar");
|
||||
this.tracedChannel.removeInterceptor(immutableMessageInterceptor);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
static class App {
|
||||
|
||||
Reference in New Issue
Block a user