Skip to content

Develop MQTT Hive

Frieder edited this page Feb 6, 2024 · 2 revisions

How to use MQTT functionality

CorreoMQTT is using the hivemq-mqtt-client library: https://hivemq.github.io/hivemq-mqtt-client/

The CorreoMQTT core is using a small wrapper around this library.

Each connection in CorreoMQTT has an internal id. This id is basically related to tab you are in. So usually the code that calls your task will provide you that id and there is already an existing client for it.

To get the client for a specific connection, just call: connectionHolder.getClient(connectionId). ConnectionHolder must be injected using DependencyInjection. This will give you a CorreoMqttClient, where you can call your mqtt functionality.

    void connect() throws InterruptedException, ExecutionException, TimeoutException, SSLException;
    void disconnect(boolean graceful);
    void publish(MessageDTO messageDTO) throws InterruptedException, ExecutionException, TimeoutException;
    void subscribe(SubscriptionDTO subscriptionDTO, Consumer<MessageDTO> incomingCallback) throws InterruptedException, ExecutionException, TimeoutException;
    void unsubscribe(SubscriptionDTO subscriptionDTO);
    Set<SubscriptionDTO> getSubscriptions();
Clone this wiki locally