Search in sources :

Example 1 with Subscription

use of net.sf.xenqtt.client.Subscription in project moleculer-java by moleculer-java.

the class MqttTransporter method subscribed.

@Override
public void subscribed(MqttClient client, Subscription[] requestedSubscriptions, Subscription[] grantedSubscriptions, boolean requestsGranted) {
    for (Subscription s : grantedSubscriptions) {
        String channel = s.getTopic();
        Promise promise = subscriptions.remove(channel);
        if (promise != null) {
            promise.complete();
        }
        if (debug) {
            logger.info("Channel \"" + channel + "\" subscribed successfully.");
        }
    }
}
Also used : Promise(services.moleculer.Promise) Subscription(net.sf.xenqtt.client.Subscription)

Example 2 with Subscription

use of net.sf.xenqtt.client.Subscription in project moleculer-java by moleculer-java.

the class MqttTransporter method subscribe.

@Override
public Promise subscribe(String channel) {
    Promise promise = new Promise();
    if (client != null) {
        try {
            client.subscribe(new Subscription[] { new Subscription(channel, qos) });
            subscriptions.put(channel, promise);
        } catch (Exception cause) {
            promise.complete(cause);
        }
    } else {
        promise.complete(new Throwable("Not connected!"));
    }
    return promise;
}
Also used : Promise(services.moleculer.Promise) Subscription(net.sf.xenqtt.client.Subscription)

Aggregations

Subscription (net.sf.xenqtt.client.Subscription)2 Promise (services.moleculer.Promise)2