Azure IOT using Eclipse Paho MQTT library in Java

Jaime 0 Reputation points
2023-07-31T14:17:05.3733333+00:00

Hello,

I have developed a Spring Boot project using the spring-integration-mqtt library which under the hood uses org.eclipse.paho.client.mqttv3. It works fine getting connected to a local MQTT that I have with the following configuration:

mqtt:
  options:
    automatic-reconnect: true
    clean-session: true
    connection-timeout: 10
    user-name: ****
    password: ****
    keep-alive-interval: 100    
  hostname: tcp://10.142.90.116:1883

Also I can connect to Azure IOT Hub using my MQTT explorer client:

MQTT client

But if I change my config file to:

mqtt:
  options:
    (...)   
  hostname: tcp://OffimanIoT.azure-devices.net/device/?api-version=2021-04-12:1883

It throws error java.lang.IllegalArgumentException: URI path must be empty "tcp://OffimanIoT.azure-devices.net/device/?api-version=2021-04-12:1883"

If I use:

mqtt:
  options:
    (...)   
  hostname: tcp://OffimanIoT.azure-devices.net

It throws Connection timeout.

And if I use:

mqtt:
  options:
    (...)   
  hostname: mqtt://OffimanIoT.azure-devices.net/device/?api-version=2021-04-12:1883

It throws java.lang.IllegalArgumentException: no NetworkModule installed for scheme "mqtt" of URI "mqtt://OffimanIoT.azure-devices.net/device/?api-version=2021-04-12:1883".

Does anyone know how to fix this? Thanks in advance for your help.

Best regards,

Jaime.

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,235 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sander van de Velde | MVP 34,686 Reputation points MVP
    2023-07-31T15:20:16.7433333+00:00

    Hello @Jaime,

    you can see how the IoT Hub supports MQTT without using any of the Azure IoT Device SDKs here.

    The example is written in C# but you get a feeling on how the specific topics are working.

    There, you see you need to provide the SAS token for a device.

    Is your device named 'device' as seen in:

    hostname: tcp://OffimanIoT.azure-devices.net/device/?api-version=2021-04-12:1883

    I'm not sure if the 'tcp://' or 'mqtt://' are working.

    Regarding the port, please check if you use 8883 as documented.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.