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(String.format("foo%s0", getDestinationNameDelimiter()), moduleOutputChannel, outputBindingProperties.getProducer()); Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("foo%s0", getDestinationNameDelimiter()), "testSendAndReceive", moduleInputChannel, inputBindingProperties.getConsumer()); Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "text/plain") .build(); binderBindUnbindLatency(); CountDownLatch latch = new CountDownLatch(1); AtomicReference<Message<byte[]>> inboundMessageRef = new AtomicReference<Message<byte[]>>(); moduleInputChannel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { try { inboundMessageRef.set((Message<byte[]>) message); } finally { latch.countDown(); } } }); moduleOutputChannel.send(message); Assert.isTrue(latch.await(5, TimeUnit.SECONDS), "Failed to receive message"); assertThat(new String(inboundMessageRef.get().getPayload(),StandardCharsets.UTF_8)).isEqualTo("foo"); assertThat(inboundMessageRef.get().getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull(); assertThat(inboundMessageRef.get().getHeaders().get(MessageHeaders.CONTENT_TYPE).toString()).isEqualTo("text/plain"); 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(String.format("foo%s0", getDestinationNameDelimiter()), moduleOutputChannel, outputBindingProperties.getProducer()); Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("foo%s0", getDestinationNameDelimiter()), "testSendAndReceive", moduleInputChannel, inputBindingProperties.getConsumer()); Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "text/plain") .build(); binderBindUnbindLatency(); CountDownLatch latch = new CountDownLatch(1); AtomicReference<Message<byte[]>> inboundMessageRef = new AtomicReference<Message<byte[]>>(); moduleInputChannel.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { try { inboundMessageRef.set((Message<byte[]>) message); } finally { latch.countDown(); } } }); moduleOutputChannel.send(message); Assert.isTrue(latch.await(5, TimeUnit.SECONDS), "Failed to receive message"); assertThat(inboundMessageRef.get().getPayload()).isEqualTo("foo".getBytes(StandardCharsets.UTF_8)); assertThat(inboundMessageRef.get().getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull(); assertThat(inboundMessageRef.get().getHeaders().get(MessageHeaders.CONTENT_TYPE).toString()).isEqualTo("text/plain"); producerBinding.unbind(); consumerBinding.unbind(); }