August 15, 2023

cMQTT – Docs for ESB 6.x

cMQTT

Sends messages to, or consumes messages from MQTT compliant message
brokers.

cMQTT Standard properties

These properties are used to configure cMQTT running in the Standard Job framework.

The Standard
cMQTT component belongs to the Connectivity/Internet of Things and Connectivity/Messaging family.

Basic settings

ConnectionFactory

This option appears when Use Connection
Factory
is selected. Click […] and select a connection factory to be used for
handling messages.

Topic Name

Type in a name for the message topic in the message broker.

Advanced settings

Parameters

Set the optional parameters in the corresponding table. Click
[+] as many times as required
to add parameters to the table. Then click the corresponding value
field and enter a value. See the site http://camel.apache.org/amqp.html for available
options.

Usage

Usage rule

cMQTT can be a start, middle or
end component in a Route. It has to be used with the cMQConnectionFactory component, which
creates a connection to a MQ server. For more information about
cMQConnectionFactory, see cMQConnectionFactory.

Limitation

Due to license incompatibility, one or more JARs required to use this component are not
provided. You can install the missing JARs for this particular component by clicking the
Install button on the Component tab view. You can also find out and add all missing JARs easily on the
Modules tab in the
Integration
perspective of your
studio. You can find more details about how to install external modules in Talend Help Center (https://help.talend.com).

Scenario: Sending messages to and receiving messages from an MQTT broker

This scenario applies only to a Talend solution with ESB.

This scenario will show you how to use the cMQTT component
to send messages to and consume messages from an MQTT broker. To do this, two Routes are
built, a message producer Route, and a consumer Route. Messages are sent to the MQTT
broker in the producer Route and then consumed in the consumer Route.

In this use case, Apache ActiveMQ is used as the message broker which supports the MQTT
protocol. You need to launch the ActiveMQ server before executing the Route. For more
information about installing and launching ActiveMQ server, see the site http://activemq.apache.org/index.html.

Building the producer Route

Dropping and linking the components

use_case-cmqtt1.png

  1. From the Palette, drag and drop a
    cMQConnectionFactory, a cTimer, a cSetBody, a cMQTT, and a
    cLog component onto the design
    workspace.
  2. Label the components for better identification of their roles and link
    them with the Row > Route connection as shown above.

Configuring the components

  1. Double-click the cMQConnectionFactory
    component to display its Basic settings
    view in the Component tab.

    use_case-cmqtt2.png

  2. From the MQ Server list, select MQTT to handle messages.

    In the Host Name field, keep the default value “127.0.0.1” as the local ActiveMQ server is
    used as the message broker in this example.
    In the Port field, keep the default
    1883.
    Keep the default settings of the other options.
  3. Double-click the cTimer component to open
    its Basic settings view in the Component tab.

    use_case-cmqtt3.png

  4. In the Repeat field, enter 5
    to generate the message exchange five times. Keep the default settings of
    the other options.
  5. Double-click the cSetBody component to
    open its Basic settings view in the
    Component tab.

    use_case-cmqtt4.png

  6. Select SIMPLE from the Language list box and type in "Hello
    world"
    in the Expression field
    as the message body.
  7. Double-click the cMQTT component to open its Basic settings view in the Component tab.

    use_case-cmqtt5.png

  8. In the ConnectionFactory field, click
    […] and select the MQ connection
    factory that you have just configured to handle messages.

    In the Topic Name field, type in a name
    for the topic, for example "mytopic".
  9. Keep the default settings of the cLog component to
    log the message exchanges.

    use_case-cmqtt6.png

  10. Press Ctrl+S to save your Route.

Viewing the code

Click the Code tab at the bottom of the
design workspace to check the generated code.

use_case-cmqtt7.png

As shown above, the message flow from cTimer_1 is given a payload by
cSetBody_1 and then sent to cMQTT_1 and
cLog_1.

Building the consumer Route

Arranging the flow of the message

use_case-cmqtt10.png

  1. From the Palette, drag and drop a cMQConnectionFactory, a cMQTT, and a cLog component
    onto the design workspace.
  2. Label the components for better identification of their roles and link
    them with the Row > Route connection as shown above.

Configuring how the message is processed

  1. Double-click the cMQConnectionFactory
    component to display its Basic settings
    view in the Component tab.

    use_case-cmqtt2.png

  2. Configure the cMQConnectionFactory
    component as the one in the producer Route to connect to the same MQTT
    broker.
  3. Double-click the cMQTT component to
    display its Basic settings view in the
    Component tab.

    use_case-cmqtt11.png

  4. In the ConnectionFactory field, click
    […] and select the MQ connection
    factory that you have just configured to handle messages.

    Specify the same Topic Name in the
    consumer cMQTT component as in the
    producer.
  5. Keep the default settings of the cLog component to
    log the message exchanges.

    use_case-cmqtt12.png

  6. Press Ctrl+S to save your Route.

Viewing the code and executing the Route

  1. Click the Code tab at the bottom of the
    design workspace to check the generated code.

    use_case-cmqtt13.png

    As shown above, the message flow is routed from cMQTT_1 to
    cLog_1.
  2. Press F6 to execute the Route. In the execution console
    you can see that there’s no message exchange yet.

    use_case-cmqtt15.png

  3. Execute the producer Route. The logs of the message exchange are printed
    in the console.

    use_case-cmqtt8.png

  4. In the consumer Route, the messages are consumed and shown in the execution
    console.

    use_case-cmqtt14.png

  5. In the ActiveMQ Web Console, you can see that the topic
    mytopic has been created and the messages are
    consumed.

    use_case-cmqtt9.png


Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x