小编Num*_*ume的帖子

使用spring集成网关向不同主题发送消息

我正在尝试使用 spring 集成将 mqtt 消息发送到代理,并且我正在尝试使用网关接口。

 @Bean
public MqttPahoClientFactory mqttClientFactory() {
    DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
    //set the factory details
    return factory:
}

@Bean
@ServiceActivator(inputChannel = "mqttOutboundChannel")
public MessageHandler mqttOutbound() {
    MqttPahoMessageHandler messageHandler =
            new MqttPahoMessageHandler("randomString", mqttClientFactory());
    //set handler details
    messageHandler.setDefaultTopic(topic);
    return messageHandler;
}

@Bean
public MessageChannel mqttOutboundChannel() {
    return new DirectChannel();
}
@MessagingGateway(defaultRequestChannel = "mqttOutboundChannel")
private interface MyGateway {
    void sendToMqtt(String data);
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:如果我想使用网关处理程序将消息发送到不同的主题,我该如何做到这一点,而不必为每个主题创建适配器?

谢谢。

希望我清楚地表达了我的问题并且代码格式正确。

spring-integration spring-integration-mqtt

5
推荐指数
1
解决办法
1231
查看次数