July 30, 2023

cJMS – Docs for ESB ESB 7.x

cJMS

Exchanges messages between a Route and a JMS provider.

cJMS Standard properties

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

The Standard
cJMS component belongs to the Connectivity family.

Basic settings

URI/Type

Select the messaging type, either queue or
topic.

URI/Destination

Type in a name for the JMS queue or topic.
ConnectionFactory Click the three-dot button and select a JMS connection factory to be used
for handling messages or enter the name of the corresponding
cMQConnectionFactory component directly in the
field.

Advanced settings

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

Usage

Usage rule

cJMS 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

 n/a

Sending and receiving a message from a JMS queue

This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.

In this scenario, a cJMS component sends messages
from the local file system to a message queue in one sub-route, and the messages are
then consumed by another cJMS component in the other
sub-route.

cJMS_1.png

Dropping and linking the components

  1. From the Palette, expand the Connectivity/Messaging folder, and drop a cMQConnectionFactory component onto the design
    workspace to specify the JMS connection factory for handling
    messages.
  2. From the Connectivity folder, drop one cFile and two cJMS components onto the design workspace.
  3. From the Custom folder, drop a cProcessor component onto the design workspace.
  4. Connect the cFile component to a
    cJMS component using a Row > Route
    connection as the message producer sub-route.
  5. Connect the other cJMS component to the
    cProcessor component using a Row > Route
    connection as the message consumer sub-route.
  6. Label the components properly for better identification of their
    functionalities.

Configuring the components

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

    cJMS_2.png

  2. From the MQ Server list, select an MQ
    server. In this use case, we use the default ActiveMQ server to handle the
    messages.

    In the Broker URI field, type in the URI
    of the message broker. Here we simply use the default URI “vm://localhost?broker.persistent=false”.
  3. In the message producer sub-route, double-click the cFile component to display its Basic
    settings
    view.

    cJMS_3.png

  4. Define the properties of the cFile
    component.

    In this use case, simply specify the path to the folder that holds the
    source file to be sent as electronic message, and leave the other parameters
    as they are.
  5. Double-click the cJMS
    component labeled Message_producer to display its
    Basic settings view.

    cJMS_4.png

  6. From the Type list, select queue to send the messages to a JMS queue.

    In the Destination field, type in a name
    for the JMS queue, "queue.hello" in this use case.
    Double-click the […] button next to ConnectionFactory. Select the MQ connection
    factory that you have just configured in the dialog box and click OK.
    cJMS_5.png

  7. Switch to the message consumer sub-route, and double click the
    cJMS component labeled Message_consumer to display its Basic
    settings
    view.

    cJMS_6.png

  8. Configure the message consumer using exactly the same parameters as in the
    message producer.
  9. Double-click the cProcessor
    component to display its Basic settings
    view.

    cJMS_7.png

  10. In the Code area, customize the code as
    shown below to display the file names of the consumed messages on the
    Run console.

  11. Press Ctrl+S to save your Routes.

Viewing code and executing the Route

  1. Click the Code tab at the bottom of the
    design workspace to have a look at the generated code.

    cJMS_8.png

    cJMS_9.png

    In the partially shown code, a message route is built from the
    File_source_cFile_1
    .to the cJMS_1 which then sends the message to a
    message queue via a broker identified by
    vm://localhost?broker.persistent=false. The message
    from the Message_consumer_cJMS_2 is processed
    by cProcessor_1.
  2. Click the Run button in the Run view to launch the execution of your Route.
    You can also press F6 to execute it.

    RESULT: The message is received by the consumer, as shown on the Run console.
    cJMS_10.png

Setting up a JMS local transaction

This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.

In this scenario, a local transaction with three steps is performed to send, test and
consume a JMS message:

  1. The first Route is used to send a “hello
    world!”
    message to feed the queue.hello JMS queue.

  2. The second Route is used to test the received JMS message. This message is
    redelivered six times to the queue.hello
    queue and is then moved to the Dead Letter
    JMS queue. The Route is programmed to throw an exception every time an exchange
    is processed by the Route.

  3. The last Route is used to consume the “hello
    world!”
    message from the Dead
    Letter
    JMS queue.

In this use case, we use the local ActiveMQ server to handle messages between
different Routes. The ActiveMQ server need to be started before executing the Routes.
For more information on installing and launching ActiveMQ server, see the Apache Web
site http://activemq.apache.org/index.html.

Sending a message to the queue.hello JMS
queue

cJMS_11.png

Dropping and linking the components

  1. From the Palette, drop the five following components
    onto the design workspace: one cMQConnectionFactory, one cConfig, one cMessagingEndpoint, one cJMS and one cProcessor
    component.
  2. Connect the cMessagingEndpoint component
    to the cJMS using a Row > Route
    connection.
  3. Connect the cJMS component to the
    cProcessor component using a Row > Route
    connection.

Configuring the components

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

    cJMS_12.png

  2. From the MQ Server list, select an MQ
    server. In this use case, we use the default ActiveMQ server to handle the
    messages.
  3. In the Broker URI field, type in Active
    MQ’s default URI of the localhost server: “tcp://localhost:61616”.
  4. Double-click the cConfig component, which
    is labelled DatasetConfig, to display its
    Basic settings view in the Component tab and set its parameters.

    cJMS_13.png

  5. Write a piece of code in the Code field
    to register the dataset instance hello
    into the registry, as shown below.

  6. Double-click the cMessagingEndpoint
    component, which is labelled SimpleDatasetGen, to display its Basic
    settings
    view in the Component tab. and set its parameters.

    cJMS_14.png

  7. In the URI field, enter
    dataset:hello between the quotation marks.
  8. Double-click the cJMS
    component labeled AMQ_Send to display its Basic settings view.

    cJMS_15.png

  9. From the Type list, select queue to send the message to a JMS queue.

    In the Destination field, type in a name
    for the JMS queue, “queue.hello” in this
    use case.
    Double-click the […] button next to ConnectionFactory. Select the MQ connection
    factory that you have just configured in the dialog box and click OK.
    cJMS_16.png

  10. Double-click the cProcessor component
    labelled PrintSendMsg to display its
    Basic settings view in the Component tab, and customize the code in the
    Code area to display the sent message
    intercepted on the console.

Executing the Route

Click the Run button in the Run view to launch the execution of your Route.
You can also press F6 to execute it.

RESULT: One “hello world!” message is
sent to the JMS Queue, as shown in the Run
console.
cJMS_17.png

Testing the received message

cJMS_18.png

Linking the components

  1. From the Palette, drop the four following components
    onto the design workspace: one cJMS, two
    cProcessor components and one cMQConnectionFactory.
  2. Connect the cJMS component to the first
    cProcessor using a Row > Route
    connection.
  3. Connect the first cProcessor component to
    the second cProcessor component using a
    Row > Route connection.

Defining the settings of the components

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

    cJMS_19.png

  2. From the MQ Server list, select an MQ
    server. In this use case, we use the default ActiveMQ server to handle the
    messages.

    Select the Use transaction check
    box.
  3. In the Broker URI field, type in Active
    MQ’s default URI of the localhost server: “tcp://localhost:61616”.
  4. Double-click the cJMS
    component labeled AMQ_Rev to display its Basic settings view.

    cJMS_20.png

  5. From the Type list, select queue to send the messages to a JMS queue.

    In the Destination field, type in a name
    for the JMS queue, “queue.hello” in this
    use case.
    Double-click the […] button next to ConnectionFactory. Select the MQ connection
    factory that you have just configured in the dialog box and click OK.
    cJMS_21.png

  6. Double-click the first cProcessor
    component labelled PrintRevMsg to display
    its Basic settings view in the Component tab, and customize the code in the
    Code area to display the received
    message intercepted on the console.

  7. Double-click the second cProcessor
    component labelled ThrowEx to display its
    Basic settings view in the Component tab, and customize the code in the
    Code area to throw the Force fail exception every time an exchange is
    processed by the route.

Running the Route

Click the Run button in the Run view to launch the execution of your Route.
You can also press F6 to execute it.

RESULT: The “hello world!” message is
tested and a rollback transaction is performed. Once the message redelivery
attempts exceeds six times, the pending message is sent to the Dead Letter JMS Queue.

Consuming the message from the DeadLetter JMS
queue

cJMS_22.png

Arranging the flow of the message

  1. From the Palette, drop the three following components
    onto the design workspace: one cMQConnectionFactory, one cJMS and one cProcessor
    component.
  2. Connect the cJMS component to the
    cProcessor component using a Row > Route
    connection.

Configuring how the message is processed

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

    cJMS_23.png

  2. From the MQ Server list, select an MQ
    server. In this use case, we use the default ActiveMQ server to handle the
    messages.
  3. In the Broker URI field, type in Active
    MQ’s default URI of the localhost server: “tcp://localhost:61616”.
  4. Double-click the cJMS
    component labeled DeadLetterQueueJMS to display its
    Basic settings view.

    cJMS_24.png

  5. From the Type list, select queue to send the messages to a JMS queue.

    In the Destination field, type in a name
    for the JMS queue, “ActiveMQ.DLQ” in this
    use case (the default Dead Letter Queue
    in ActiveMQ).
    Double-click the […] button next to ConnectionFactory. Select the MQ connection
    factory that you have just configured in the dialog box and click OK.
    cJMS_25.png

  6. Double-click the cProcessor component
    labelled PrintMsg to display its
    Basic settings view in the Component tab, and customize the code in the
    Code area to display the received
    message intercepted on the console.

Launching the execution of the Route

Click the Run button in the Run view to launch the execution of your Route.
You can also press F6 to execute it.

RESULT: The “hello world!” message that
was in the Dead Letter queue is consumed,
as shown in the Run console.
cJMS_26.png

Sending and receiving a scheduled delivery of messages from a JMS Queue
using Camel Quartz

This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.

This scenario will show you how to use the Camel Quartz component to provide a
scheduled delivery of messages from a JMS Queue.

To do this, we will build two Routes, a message producer Route and a consumer Route.
We will implement the Quartz component in the producer Route to send scheduled messages
to a JMS Queue. The messages are then consumed by the consumer Route.

In this use case, we will use Apache ActiveMQ as the message broker. We 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

cJMS_27.png

  1. From the Palette, drag and drop a cMQConnectionFactory, a cJMS, a cSetBody, and two
    cMessagingEndpoint components 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.

    cJMS_28.png

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

    In the Broker URI field, type in the URI
    of the local Active MQ server, “tcp://localhost:61616”.
    Select the Use PooledConnectionFatory
    check box and keep the default settings.
  3. Double-click the quartzConsumer component
    to open its Basic settings view in the
    Component tab.

    cJMS_29.png

  4. In the URI field, enter the code
    "quartz://HelloWorld?trigger.repeatInterval=2000&trigger.repeatCount=-1"
    to define a timer for starting message exchanges. In this use case, we want
    the message to be delivered endlessly between an interval of two seconds.
    For more information about Quartz, see the site http://camel.apache.org/quartz.html.
  5. Click the Advanced settings view. Click

    cJMS_30.png

    at the bottom of the Dependencies list to add a row and select
    quartz from the drop-down list. For more information about
    the Quartz component, see the site http://camel.apache.org/quartz.html.

    cJMS_31.png

  6. Double-click the cSetBody component to
    open its Basic settings view in the
    Component tab.

    cJMS_32.png

  7. Select Simple from the Language list box and type in "Hello
    world"
    in the Expression
    field.
  8. Double-click the logMessage component to
    open its Basic settings view in the
    Component tab.

    cJMS_33.png

  9. In the URI field, enter
    "log:quartzMessage" where the message exchanges are
    logged.
  10. Double-click the jmsProducer
    component to display its Basic settings
    view in the Component tab.

    cJMS_34.png

  11. From the Type list, select queue to send the messages to a JMS queue.

    In the Destination field, type in a name
    for the JMS queue, "quartzTest" in this use case.
    In the ConnectionFactory field, click […] and select the MQ connection factory that
    you have just configured.
  12. 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.

    cJMS_35.png

    As shown above, the message flow from quartzConsumer is given
    a payload by cSetBody_1 and then sent to
    logMessage and jmsProducer.
  2. Press F6 to execute the Route.

    RESULT: The logs of the message exchange are printed in the
    console.
    cJMS_36.png

Building the consumer Route

Arranging the flow of the message

cJMS_37.png

  1. From the Palette, drag and drop a cMQConnectionFactory, a cJMS, and a cMessagingEndpoint 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.

    cJMS_28.png

  2. Configure the cMQConnectionFactory component the same as
    in the producer Route.
  3. Double-click the jmsConsumer
    component to display its Basic settings
    view in the Component tab.
  4. Configure the jmsConsumer component the
    same as the jmsProducer component in the
    producer Route to consume the messages in the defined queue
    "quartzTest".
  5. Double-click the logMessage component to
    open its Basic settings view in the
    Component tab.

    cJMS_33.png

  6. In the URI field, enter
    "log:quartzMessage" where the message exchanges are
    logged.
  7. Press Ctrl+S to save your Route.

Executing the Route

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

    cJMS_40.png

    As shown above, the message flow is routed from jmsConsumer
    to logMessage.
  2. Press F6 to execute the Route.

    RESULT: The logs of the message exchange are printed in the
    console.
    cJMS_41.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