Spring boot paho mqtt клиент не публикует сообщения на rabbitmq в macos - PullRequest
0 голосов
/ 15 октября 2019

Spring boot service не публикует сообщения для брокера rabbitmq в macOS, но когда я попробовал тот же самый файл jar сборки в windows, он работает.

Используется библиотека org.eclipse.paho: org.eclipse.paho. client.mqttv3: 1.1.0 и Spring boot verion 2.1.4.BUILD-SNAPSHOT

java версия "1.8.0_181" macOS - Sierra

@SpringBootApplication
@EnableScheduling
public class DeviceEmulatorApplication {

    public static void main(String[] args) {
        SpringApplication.run(DeviceEmulatorApplication.class, args);
    }

    @Bean
    public MqttPahoClientFactory mqttClientFactory() {

        DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
        MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
        mqttConnectOptions.setUserName("rabbit");
        mqttConnectOptions.setPassword("rabbit".toCharArray());
        mqttConnectOptions.setServerURIs(new String[]{"tcp://" + "mqtt.iot.ideamart.io" + ":" + 1883});
        factory.setConnectionOptions(mqttConnectOptions);
        return factory;
    }

    @Bean
    @ServiceActivator(inputChannel = "mqttOutboundChannel")
    public MqttPahoMessageHandler mqttOutbound() {
        MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler("gygyguygug", mqttClientFactory());
        messageHandler.setAsync(true);
        return messageHandler;
    }

    @Bean
    public MessageChannel mqttOutboundChannel() {
        return new DirectChannel();
    }
}

Реализована служба для публикации сообщений

 @Override
    public void publishMessage(String message, String publishTopic) {
        if ( publishTopic.contains("pcs") ) {
            message = message + MDC.get("UUID");
        }
        try {
            gateway.sendToMqtt(MessageBuilder.withPayload(message).setHeader(MqttHeaders.TOPIC, publishTopic).build());
            logger.info("Published topic : {}, message : {}.", publishTopic, message);
        } catch (IllegalArgumentException e) {
            logger.error("Message publish exception {}.", e.getMessage());
        }
    }

Вывод

2019-10-15 10:18:43.150  INFO 42395 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {message-handler:deviceEmulatorApplication.mqttOutbound.serviceActivator} as a subscriber to the 'mqttOutboundChannel' channel
2019-10-15 10:18:43.150  INFO 42395 --- [           main] o.s.integration.channel.DirectChannel    : Channel 'application.mqttOutboundChannel' has 1 subscriber(s).
2019-10-15 10:18:43.150  INFO 42395 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started deviceEmulatorApplication.mqttOutbound.serviceActivator
2019-10-15 10:18:43.150  INFO 42395 --- [           main] ProxyFactoryBean$MethodInvocationGateway : started publisherServiceImpl$MyGateway
2019-10-15 10:18:43.151  INFO 42395 --- [           main] o.s.i.gateway.GatewayProxyFactoryBean    : started publisherServiceImpl$MyGateway
2019-10-15 10:18:43.228  INFO 42395 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8082 (http) with context path ''
2019-10-15 10:18:43.237  INFO 42395 --- [           main] c.e.d.DeviceEmulatorApplication          : Started DeviceEmulatorApplication in 5.749 seconds (JVM running for 6.595)
2019-10-15 10:18:52.262  INFO 42395 --- [   scheduling-1] com.example.deviceEmulator.Scheduler     : error occurred in message handler [mqttOutbound]; nested exception is org.springframework.messaging.MessagingException: Failed to connect; nested exception is Unexpected error (6)
2019-10-15 10:18:58.198  INFO 42395 --- [   scheduling-1] com.example.deviceEmulator.Scheduler     : error occurred in message handler [mqttOutbound]; nested exception is org.springframework.messaging.MessagingException: Failed to connect; nested exception is Unexpected error (6)
2019-10-15 10:19:04.195

Я могу публиковать сообщения в теме, используя приложения 3-ей части, такие как MQTTBox, но не работая с весенней загрузкой в ​​macOS. Кто-нибудь сталкивался с этим или это проблема с разрешениями в macOS?

...