Search in sources :

Example 6 with StreamListenerMessageHandler

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();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) DirectChannel(org.springframework.integration.channel.DirectChannel) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) StreamListenerMessageHandler(org.springframework.cloud.stream.binding.StreamListenerMessageHandler) Test(org.junit.Test)

Aggregations

StreamListenerMessageHandler (org.springframework.cloud.stream.binding.StreamListenerMessageHandler)6 QueueChannel (org.springframework.integration.channel.QueueChannel)6 Test (org.junit.Test)5 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)5 DirectChannel (org.springframework.integration.channel.DirectChannel)5 MessageChannel (org.springframework.messaging.MessageChannel)5 Message (org.springframework.messaging.Message)3 Method (java.lang.reflect.Method)1 Readings (org.springframework.cloud.stream.binder.AbstractBinderTests.Station.Readings)1 CompositeMessageConverterFactory (org.springframework.cloud.stream.converter.CompositeMessageConverterFactory)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 PayloadArgumentResolver (org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver)1 HandlerMethodArgumentResolverComposite (org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite)1 InvocableHandlerMethod (org.springframework.messaging.handler.invocation.InvocableHandlerMethod)1