Search in sources :

Example 1 with DefaultPahoMessageConverter

use of org.springframework.integration.mqtt.support.DefaultPahoMessageConverter in project spring-integration by spring-projects.

the class AbstractMqttMessageHandler method onInit.

@Override
protected void onInit() throws Exception {
    super.onInit();
    if (this.topicProcessor instanceof BeanFactoryAware && getBeanFactory() != null) {
        ((BeanFactoryAware) this.topicProcessor).setBeanFactory(getBeanFactory());
    }
    if (this.qosProcessor instanceof BeanFactoryAware && getBeanFactory() != null) {
        ((BeanFactoryAware) this.qosProcessor).setBeanFactory(getBeanFactory());
    }
    if (this.retainedProcessor instanceof BeanFactoryAware && getBeanFactory() != null) {
        ((BeanFactoryAware) this.retainedProcessor).setBeanFactory(getBeanFactory());
    }
    if (this.converter == null) {
        DefaultPahoMessageConverter defaultConverter = new DefaultPahoMessageConverter(this.defaultQos, this.qosProcessor, this.defaultRetained, this.retainedProcessor);
        if (getBeanFactory() != null) {
            defaultConverter.setBeanFactory(getBeanFactory());
        }
        this.converter = defaultConverter;
    }
}
Also used : BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) DefaultPahoMessageConverter(org.springframework.integration.mqtt.support.DefaultPahoMessageConverter)

Example 2 with DefaultPahoMessageConverter

use of org.springframework.integration.mqtt.support.DefaultPahoMessageConverter in project spring-integration by spring-projects.

the class AbstractMqttMessageDrivenChannelAdapter method onInit.

@Override
protected void onInit() {
    super.onInit();
    if (this.converter == null) {
        DefaultPahoMessageConverter pahoMessageConverter = new DefaultPahoMessageConverter();
        pahoMessageConverter.setBeanFactory(getBeanFactory());
        this.converter = pahoMessageConverter;
    }
}
Also used : DefaultPahoMessageConverter(org.springframework.integration.mqtt.support.DefaultPahoMessageConverter)

Example 3 with DefaultPahoMessageConverter

use of org.springframework.integration.mqtt.support.DefaultPahoMessageConverter in project sinsim by WilsonHu.

the class MqttService method inbound.

@Bean
public MessageProducer inbound() {
    String addressFormat = "tcp://%s:1883";
    MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(String.format(addressFormat, brokerHost), "server", "topic/client/send/#");
    adapter.setCompletionTimeout(5000);
    adapter.setConverter(new DefaultPahoMessageConverter());
    adapter.setQos(1);
    adapter.setOutputChannel(mqttInputChannel());
    return adapter;
}
Also used : DefaultPahoMessageConverter(org.springframework.integration.mqtt.support.DefaultPahoMessageConverter) MqttPahoMessageDrivenChannelAdapter(org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter) Bean(org.springframework.context.annotation.Bean)

Example 4 with DefaultPahoMessageConverter

use of org.springframework.integration.mqtt.support.DefaultPahoMessageConverter in project spring-integration-samples by spring-projects.

the class Application method mqttInbound.

@Bean
public MessageProducerSupport mqttInbound() {
    MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter("siSampleConsumer", mqttClientFactory(), "siSampleTopic");
    adapter.setCompletionTimeout(5000);
    adapter.setConverter(new DefaultPahoMessageConverter());
    adapter.setQos(1);
    return adapter;
}
Also used : DefaultPahoMessageConverter(org.springframework.integration.mqtt.support.DefaultPahoMessageConverter) MqttPahoMessageDrivenChannelAdapter(org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter) Bean(org.springframework.context.annotation.Bean)

Example 5 with DefaultPahoMessageConverter

use of org.springframework.integration.mqtt.support.DefaultPahoMessageConverter in project spring-integration by spring-projects.

the class MqttOutboundChannelAdapterParserTests method testWithDefaultConverter.

@Test
public void testWithDefaultConverter() {
    GenericMessage<String> message = new GenericMessage<>("foo");
    assertEquals("tcp://localhost:1883", TestUtils.getPropertyValue(withDefaultConverterHandler, "url"));
    assertEquals("foo", TestUtils.getPropertyValue(withDefaultConverterHandler, "clientId"));
    assertEquals("bar", TestUtils.getPropertyValue(withDefaultConverterHandler, "defaultTopic"));
    assertEquals(1, TestUtils.getPropertyValue(withDefaultConverterHandler, "defaultQos"));
    assertEquals(Boolean.TRUE, TestUtils.getPropertyValue(withDefaultConverterHandler, "defaultRetained", Boolean.class));
    DefaultPahoMessageConverter defaultConverter = TestUtils.getPropertyValue(withDefaultConverterHandler, "converter", DefaultPahoMessageConverter.class);
    assertEquals(1, defaultConverter.fromMessage(message, null).getQos());
    assertTrue(defaultConverter.fromMessage(message, null).isRetained());
    assertSame(clientFactory, TestUtils.getPropertyValue(withDefaultConverterHandler, "clientFactory"));
    assertTrue(TestUtils.getPropertyValue(withDefaultConverterHandler, "async", Boolean.class));
    assertTrue(TestUtils.getPropertyValue(withDefaultConverterHandler, "asyncEvents", Boolean.class));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) DefaultPahoMessageConverter(org.springframework.integration.mqtt.support.DefaultPahoMessageConverter) Test(org.junit.Test)

Aggregations

DefaultPahoMessageConverter (org.springframework.integration.mqtt.support.DefaultPahoMessageConverter)6 MqttPahoMessageDrivenChannelAdapter (org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter)3 Test (org.junit.Test)2 Bean (org.springframework.context.annotation.Bean)2 BeanFactory (org.springframework.beans.factory.BeanFactory)1 BeanFactoryAware (org.springframework.beans.factory.BeanFactoryAware)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 MqttPahoMessageHandler (org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler)1 EmbeddedJsonHeadersMessageMapper (org.springframework.integration.support.json.EmbeddedJsonHeadersMessageMapper)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)1