You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

MQTT Component

The mqtt: component is used for communicating with MQTT compliant message brokers, like Apache ActiveMQ or Mosquitto

Camel will poll the feed every 60 seconds by default.
Note: The component currently only supports polling (consuming) feeds.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-mqtt</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

mqtt://name[?options]

Where name is the name you want to assign the component.

Options

Unknown macro: {div}

Property

Default

Description

QoS

AtLeastOnce

The MQTT Quality of Service to use for message exchanges. It can be one of AtMostOnce, AtLeastOnce or ExactlyOnce

subscribeTopicName

 

The name of the Topic to subscribe to for messages

publishTopicName

camel/mqtt/test

The default Topic to publish messages on

byDefaultRetain

false

The default retain policy to be used on messages sent to the MQTT broker

mqttTopicPropertyName

_MQTTTopicPropertyName+

The property name to look for on an Exchange for an individual published message. If this is set - the name will be used as the Topic to publish a message to the MQTT message broker.

mqttRetainPropertyName

MQTTRetain

The property name to look for on an Exchange for an individual published message. If this is set (expects a Boolean value) - then the retain property will be set on the message sent to the MQTT message broker.

mqttQosPropertyName

MQTTQos

The property name to look for on an Exchange for an individual published message. If this is set (one of AtMostOnce, AtLeastOnce or ExactlyOnce ) - then that QoS will be set on the message sent to the MQTT message broker.

connectWaitInSeconds

10

Delay in seconds the Component will wait for a connection to be established to the MQTT broker

disconnectWaitInSeconds

5

the number of seconds the Component will wait for a valid disconnect on stop() from the MQTT broker

sendWaitInSeconds

5

The maximum time the Component will wait for a receipt from the MQTT broker to acknowledge a published message before throwing an exception

You can append query options to the URI in the following format, ?option=value&option=value&...

Samples

Sending messages:

from("direct:foo").to("mqtt:cheese?publishTopicName=test.mqtt.topic");

Consuming messages:

from("mqtt:bar?subscribeTopicName=test.mqtt.topic").transform(body().convertToString()).to("mock:result")

Endpoints

Camel supports the Message Endpoint pattern using the Endpoint interface. Endpoints are usually created by a Component and Endpoints are usually referred to in the DSL via their URIs.

From an Endpoint you can use the following methods

See Also

  • No labels