use of org.springframework.integration.mqtt.support.DefaultPahoMessageConverter in project spring-integration by spring-projects.
the class BackToBackAdapterTests method testJson.
@Test
public void testJson() {
MqttPahoMessageHandler adapter = new MqttPahoMessageHandler("tcp://localhost:1883", "si-test-out");
adapter.setDefaultTopic("mqtt-foo");
adapter.setBeanFactory(mock(BeanFactory.class));
EmbeddedJsonHeadersMessageMapper mapper = new EmbeddedJsonHeadersMessageMapper(JacksonJsonUtils.messagingAwareMapper("org.springframework"));
DefaultPahoMessageConverter converter = new DefaultPahoMessageConverter();
converter.setBytesMessageMapper(mapper);
adapter.setConverter(converter);
adapter.afterPropertiesSet();
adapter.start();
MqttPahoMessageDrivenChannelAdapter inbound = new MqttPahoMessageDrivenChannelAdapter("tcp://localhost:1883", "si-test-in", "mqtt-foo");
QueueChannel outputChannel = new QueueChannel();
inbound.setOutputChannel(outputChannel);
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.initialize();
inbound.setTaskScheduler(taskScheduler);
inbound.setBeanFactory(mock(BeanFactory.class));
inbound.setConverter(converter);
inbound.afterPropertiesSet();
inbound.start();
adapter.handleMessage(new GenericMessage<Foo>(new Foo("bar"), Collections.singletonMap("baz", "qux")));
Message<?> out = outputChannel.receive(20000);
assertNotNull(out);
adapter.stop();
inbound.stop();
assertEquals(new Foo("bar"), out.getPayload());
assertEquals("mqtt-foo", out.getHeaders().get(MqttHeaders.RECEIVED_TOPIC));
assertEquals("qux", out.getHeaders().get("baz"));
}
Aggregations