use of org.springframework.cloud.stream.binding.StreamListenerMessageHandler 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();
}
use of org.springframework.cloud.stream.binding.StreamListenerMessageHandler in project spring-cloud-stream by spring-cloud.
the class AbstractBinderTests method testSendJsonReceivePojoWithStreamListener.
@SuppressWarnings("rawtypes")
@Test
public void testSendJsonReceivePojoWithStreamListener() 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%s0d", getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0d", getDestinationNameDelimiter()), "test-4", 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<Station> reply = (Message<Station>) channel.receive(5000);
assertNotNull(reply);
assertTrue(reply.getPayload() instanceof Station);
producerBinding.unbind();
consumerBinding.unbind();
}
use of org.springframework.cloud.stream.binding.StreamListenerMessageHandler in project spring-cloud-stream by spring-cloud.
the class AbstractBinderTests method testSendPojoReceivePojoKryoWithStreamListener.
@SuppressWarnings("rawtypes")
@Test
public void testSendPojoReceivePojoKryoWithStreamListener() 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%s0b", getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0b", getDestinationNameDelimiter()), "test-2", moduleInputChannel, consumerBindingProperties.getConsumer());
Station station = new Station();
Message<?> message = MessageBuilder.withPayload(station).setHeader(MessageHeaders.CONTENT_TYPE, MessageConverterUtils.X_JAVA_OBJECT).build();
moduleInputChannel.subscribe(handler);
moduleOutputChannel.send(message);
QueueChannel replyChannel = (QueueChannel) handler.getOutputChannel();
Message<?> replyMessage = replyChannel.receive(5000);
assertTrue(replyMessage.getPayload() instanceof Station);
producerBinding.unbind();
consumerBinding.unbind();
}
use of org.springframework.cloud.stream.binding.StreamListenerMessageHandler in project spring-cloud-stream by spring-cloud.
the class AbstractBinderTests method buildStreamListener.
private StreamListenerMessageHandler buildStreamListener(Class<?> handlerClass, String handlerMethodName, Class<?>... parameters) throws Exception {
String channelName = "reply_" + System.nanoTime();
GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton(channelName, new QueueChannel());
Method m = ReflectionUtils.findMethod(handlerClass, handlerMethodName, parameters);
InvocableHandlerMethod method = new InvocableHandlerMethod(this, m);
HandlerMethodArgumentResolverComposite resolver = new HandlerMethodArgumentResolverComposite();
CompositeMessageConverterFactory factory = new CompositeMessageConverterFactory();
resolver.addResolver(new PayloadArgumentResolver(factory.getMessageConverterForAllRegistered()));
method.setMessageMethodArgumentResolvers(resolver);
Constructor<?> c = ReflectionUtils.accessibleConstructor(StreamListenerMessageHandler.class, InvocableHandlerMethod.class, boolean.class, String[].class);
StreamListenerMessageHandler handler = (StreamListenerMessageHandler) c.newInstance(method, false, new String[] {});
handler.setOutputChannelName(channelName);
handler.setBeanFactory(context);
handler.afterPropertiesSet();
context.refresh();
return handler;
}
use of org.springframework.cloud.stream.binding.StreamListenerMessageHandler in project spring-cloud-stream by spring-cloud.
the class AbstractBinderTests method testSendPojoReceivePojoWithStreamListenerDefaultContentType.
@SuppressWarnings("rawtypes")
@Test
public void testSendPojoReceivePojoWithStreamListenerDefaultContentType() 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%s0a", getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0a", getDestinationNameDelimiter()), "test-1", moduleInputChannel, consumerBindingProperties.getConsumer());
Station station = new Station();
Message<?> message = MessageBuilder.withPayload(station).build();
moduleInputChannel.subscribe(handler);
moduleOutputChannel.send(message);
QueueChannel replyChannel = (QueueChannel) handler.getOutputChannel();
Message<?> replyMessage = replyChannel.receive(5000);
assertTrue(replyMessage.getPayload() instanceof Station);
producerBinding.unbind();
consumerBinding.unbind();
}
Aggregations