HiveMq client Migration from Paho client

Hi,
I am trying to replace the existing paho client with hiveMq client.

Now we have an implementation using paho client like:

client.setCallback(new MqttCallbackExtended {

          override def deliveryComplete(token: IMqttDeliveryToken): Unit = ()

          override def connectionLost(cause: Throwable): Unit = ()

          override def connectComplete(reconnect: Boolean, serverURI: String): Unit = {}

          override def messageArrived(topic: String, message: MqttMessage): Unit =   {}
       }

Here paho client provides an interface MqttCallbackExtended and an interface method messageArrived()

Here we can receive all the subscribed topic messages.

Is there any similar replacement for hiveMq client?

I am trying to do the same with hiveMq client. Is any replacement interface available in hiveMQ client?
Any suggestion would be appreciated.
Thanks

Hi @ANJ ,

HiveMQ MQTT Client offers 3 different flavours of API:

  • Blocking
  • Asynchronous
  • Reactive

Each of them has its own interface, you can pick one that fits your requirements and it is possible to switch the API flavour at any time and use different API flavours of the same client concurrently. More info: API Flavours.

Check out the Quick Start chapter to get started with asynchronous API flavour. For example, it shows how to define a callback function in order to process received messages is shown in the chapter Subscribing to a topic:

Given a client which has successfully connected to a broker, you can setup your subscriptions:

client.subscribeWith()
        .topicFilter("the/topic")
        .callback(publish -> {
            // Process the received message
        })
        .send()
        .whenComplete((subAck, throwable) -> {
            if (throwable != null) {
                // Handle failure to subscribe
            } else {
                // Handle successful subscription, e.g. logging or incrementing a metric
            }
        });

You can find more examples in the hivemq-mqtt-client repo: hivemq-mqtt-client/examples/src/main/java/com/hivemq/client/mqtt/examples at master · hivemq/hivemq-mqtt-client · GitHub.

Let me know if this helps!

Kind regards,
Dasha from HiveMQ team

Hi @Daria_H

This will not help me in my scenario.

I am looking for an interface where I can receive all incoming messages in one place. The topics can be subscribed to anywhere in the code. like

client.subscribe(topic1)

client.subscribe(topic2)

client.subscribe(topic3)

But the incoming messages for topic1, topic2, and topic3 will be in one place. And I don’t want to subscribe to all the topics at once.