Search in sources :

Example 1 with Readings

use of org.springframework.cloud.stream.binder.AbstractBinderTests.Station.Readings in project spring-cloud-stream by spring-cloud.

the class AbstractBinderTests method testSendPojoReceivePojoWithStreamListener.

@SuppressWarnings("rawtypes")
@Test
public void testSendPojoReceivePojoWithStreamListener() throws Exception {
    StreamListenerMessageHandler handler = this.buildStreamListener(AbstractBinderTests.class, "echoStation", Station.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%s0f", getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
    Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0f", getDestinationNameDelimiter()), "test-6", moduleInputChannel, consumerBindingProperties.getConsumer());
    Readings r1 = new Readings();
    r1.setCustomerid("123");
    r1.setStationid("XYZ");
    Readings r2 = new Readings();
    r2.setCustomerid("546");
    r2.setStationid("ABC");
    Station station = new Station();
    station.setReadings(Arrays.asList(r1, r2));
    Message<?> message = MessageBuilder.withPayload(station).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build();
    moduleInputChannel.subscribe(handler);
    moduleOutputChannel.send(message);
    QueueChannel channel = (QueueChannel) handler.getOutputChannel();
    Message<Station> reply = (Message<Station>) channel.receive(5000);
    assertNotNull(reply);
    assertTrue(reply.getPayload() instanceof Station);
    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) Readings(org.springframework.cloud.stream.binder.AbstractBinderTests.Station.Readings) StreamListenerMessageHandler(org.springframework.cloud.stream.binding.StreamListenerMessageHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Readings (org.springframework.cloud.stream.binder.AbstractBinderTests.Station.Readings)1 StreamListenerMessageHandler (org.springframework.cloud.stream.binding.StreamListenerMessageHandler)1 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 Message (org.springframework.messaging.Message)1 MessageChannel (org.springframework.messaging.MessageChannel)1