Source:
public void testSendAndReceive() throws Exception { Binder binder = getBinder(); BindingProperties outputBindingProperties = createProducerBindingProperties(createProducerProperties()); DirectChannel moduleOutputChannel = createBindableChannel("output", outputBindingProperties); BindingProperties inputBindingProperties = createConsumerBindingProperties(createConsumerProperties()); DirectChannel moduleInputChannel = createBindableChannel("input", inputBindingProperties); Binding<MessageChannel> producerBinding = binder.bindProducer("foo.0", moduleOutputChannel, outputBindingProperties.getProducer()); Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo.0", "testSendAndReceive", moduleInputChannel, createConsumerProperties()); Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar") .build(); binderBindUnbindLatency(); CountDownLatch latch = new CountDownLatch(1); AtomicReference<Message<String>> inboundMessageRef = new AtomicReference<Message<String>>(); moduleInputChannel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { try { inboundMessageRef.set((Message<String>) message); } finally { latch.countDown(); } } }); moduleOutputChannel.send(message); Assert.isTrue(latch.await(5, TimeUnit.SECONDS), "Failed to receive message"); assertThat(inboundMessageRef.get().getPayload()).isEqualTo("foo"); assertThat(inboundMessageRef.get().getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull(); assertThat(inboundMessageRef.get().getHeaders().get(MessageHeaders.CONTENT_TYPE)).isEqualTo("foo/bar"); producerBinding.unbind(); consumerBinding.unbind(); }

Target:
public void testSendAndReceive() throws Exception { Binder binder = getBinder(); BindingProperties outputBindingProperties = createProducerBindingProperties(createProducerProperties()); DirectChannel moduleOutputChannel = createBindableChannel("output", outputBindingProperties); BindingProperties inputBindingProperties = createConsumerBindingProperties(createConsumerProperties()); DirectChannel moduleInputChannel = createBindableChannel("input", inputBindingProperties); Binding<MessageChannel> producerBinding = binder.bindProducer("foo.0", moduleOutputChannel, outputBindingProperties.getProducer()); Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo.0", "testSendAndReceive", moduleInputChannel, createConsumerProperties()); Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar") .build(); binderBindUnbindLatency(); CountDownLatch latch = new CountDownLatch(1); AtomicReference<Message<String>> inboundMessageRef = new AtomicReference<Message<String>>(); moduleInputChannel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { try { inboundMessageRef.set((Message<String>) message); } finally { latch.countDown(); } } }); moduleOutputChannel.send(message); Assert.isTrue(latch.await(5, TimeUnit.SECONDS), "Failed to receive message"); assertThat(inboundMessageRef.get().getPayload()).isEqualTo("foo"); assertThat(inboundMessageRef.get().getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull(); assertThat(inboundMessageRef.get().getHeaders().get(MessageHeaders.CONTENT_TYPE).toString()).isEqualTo("foo/bar"); producerBinding.unbind(); consumerBinding.unbind(); }