Search in sources :

Example 1 with IMqttDeliveryToken

use of org.eclipse.paho.client.mqttv3.IMqttDeliveryToken in project camel by apache.

the class PahoConsumer method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    String topic = getEndpoint().getTopic();
    getEndpoint().getClient().subscribe(topic);
    getEndpoint().getClient().setCallback(new MqttCallback() {

        @Override
        public void connectionLost(Throwable cause) {
            LOG.debug("MQTT broker connection lost due " + cause.getMessage(), cause);
        }

        @Override
        public void messageArrived(String topic, MqttMessage message) throws Exception {
            LOG.debug("Message arrived on topic: {} -> {}", topic, message);
            Exchange exchange = getEndpoint().createExchange(message, topic);
            getAsyncProcessor().process(exchange, new AsyncCallback() {

                @Override
                public void done(boolean doneSync) {
                // noop
                }
            });
        }

        @Override
        public void deliveryComplete(IMqttDeliveryToken token) {
            LOG.debug("Delivery complete. Token: {}", token);
        }
    });
}
Also used : Exchange(org.apache.camel.Exchange) MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) AsyncCallback(org.apache.camel.AsyncCallback) MqttCallback(org.eclipse.paho.client.mqttv3.MqttCallback) IMqttDeliveryToken(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken)

Aggregations

AsyncCallback (org.apache.camel.AsyncCallback)1 Exchange (org.apache.camel.Exchange)1 IMqttDeliveryToken (org.eclipse.paho.client.mqttv3.IMqttDeliveryToken)1 MqttCallback (org.eclipse.paho.client.mqttv3.MqttCallback)1 MqttMessage (org.eclipse.paho.client.mqttv3.MqttMessage)1