use of org.springframework.cloud.stream.binding.StreamListenerMessageHandler in project spring-cloud-stream by spring-cloud.
the class AbstractBinderTests method testSendJsonReceiveJsonWithStreamListener.
@SuppressWarnings("rawtypes")
@Test
public void testSendJsonReceiveJsonWithStreamListener() throws Exception {
StreamListenerMessageHandler handler = this.buildStreamListener(AbstractBinderTests.class, "echoStationString", String.class);
Binder binder = getBinder();
BindingProperties producerBindingProperties = createProducerBindingProperties(createProducerProperties());
DirectChannel moduleOutputChannel = createBindableChannel("output", producerBindingProperties);
BindingProperties consumerBindingProperties = createConsumerBindingProperties(createConsumerProperties());
DirectChannel moduleInputChannel = createBindableChannel("input", consumerBindingProperties);
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("bad%s0e", getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0e", getDestinationNameDelimiter()), "test-5", moduleInputChannel, consumerBindingProperties.getConsumer());
String value = "{\"readings\":[{\"stationid\":\"fgh\"," + "\"customerid\":\"12345\",\"timestamp\":null},{\"stationid\":\"hjk\",\"customerid\":\"222\",\"timestamp\":null}]}";
Message<?> message = MessageBuilder.withPayload(value).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build();
moduleInputChannel.subscribe(handler);
moduleOutputChannel.send(message);
QueueChannel channel = (QueueChannel) handler.getOutputChannel();
Message<String> reply = (Message<String>) channel.receive(5000);
assertNotNull(reply);
assertTrue(reply.getPayload() instanceof String);
producerBinding.unbind();
consumerBinding.unbind();
}
Aggregations