How to install Apache ActiveMQ and use it with Talend

ActiveMQ is an open-source, messaging software which can serve as the backbone for an architecture of distributed applications built upon messaging. The creators of ActiveMQ were driven to create this open-source project for two main reasons:

  1. The available existing solutions at the time were proprietary/very expensive
  2. Developers with the Apache Software Foundation were working on a fully J2EE compliant application server (Geronimo) and they needed a JMS solution that had a license compatible with Apache’s licensing.

1. Install Apache ActiveMQ

1.1 Download the software

  • Download the latest stable release
  • Unzip the software. I have unzipped it to C:\apache-activemq-5.15.2

1.2 Set your JAVA_HOME environment variable

  • Right click “This PC” and select properties
  • Go to “Advanced system settings” –> “Environment Variables”
  • Create a new system variable:

ActiveMQ set java home

You can use “Progra~2” (Program Files (x86)) when you are using a 64 bit environment or “Progra~1” for a 32 bit environment (Program Files).

1.3 Start your ActiveMQ environment

  • Open your command prompt
  • cd [activemq_install_dir]. In my example it’s “cd C:\apache-activemq-5.15.2”
  • type: bin\activemq start

1.4 Open ActiveMQ in your browser

  • Go to http://yourIP:8161/admin
  • Login with username: admin password: admin
  • Select Queues

ActiveMQ

2. Build a simple job

In this chapter you are going to add a simple XML message to ActiveMQ. Therefore you need to start your Talend Open Studio for ESB.

2.1 Create a new job

  • Name your job “how_to_post_message_ActiveMQ”

2.2 Add tFixedFlowInput component

  • Add the tFixedFlowInput component to your canvas
  • Select the tFixedFlowInput component and open the component tab
  • Edit the schema

ActiveMQ schema

  • Select mode “Use inline Content (delimited file)”
  • Add ; as Field Separator
  • Add content 1;ActiveMQ_Example

ActiveMQ tFixedFlowInput

2.3 Add tXMLMap to canvas

  • Drag and drop the tXMLMap component to the canvas
  • Connect the tFixedFlowInput to the tXMLMap component (Row – Main)
  • Open your tXMLMap component
  • Add output table “out1”
  • Add attribute “messageContent” of the document type

  • Rename the root of your messageContent to “TalendHowTo”
  • Add sub-element “jobs” by right clicking “TalendHowTo” and choose “Create Sub-Element”

ActiveMQ tXMLMap sub element

  • Now add sub-element “job” by right clicking “Jobs” and choose “Create Sub-Element”
  • Add attribute “id” by right clicking “job” and choose “Create attribute”
  • Add sub-element “jobname” by right clicking “job” and choose “Create Sub-Element”
  • Drag and drop row1.id to your id attribute
  • Drag and drop row1.jobname to jobname sub-element
  • Right click your “job” sub-element and select “as loop element”. You could skip this step in this example because we are only using one row in our example data.

ActiveMQ loop

Your XML-tree should look like this:

ActiveMQ XML tree

2.4 Add tConvertType

After this step you are going to add the tJMSOutput component that needs a string as input value. Therefore you have to convert the document type to a string value.

  • Add the tConvertType component
  • Connect the tXMLMap to the tConvertType component (Row – out1)
  • Select “auto cast” in the component tab

ActiveMQ autocast

  • Edit the schema

ActiveMQ tConvertType edit schema

2.5 Add tJMSOutput

  • Add the tJMSOutput component next to your tConvertType component
  • Connect the tConvertType component to the tJMSOutput component
  • Go to the component tab of your tJMSOutput component and press “sync columns”
  • Select module list “activemq-all-5.14.5.jar” or a newer version
  • Select message type Queue””
  • Add “TalendHowTo” to the to field

ActiveMQ tJMSOutput

2.6 Run your job

Run your job and see the result in ActiveMQ

ActiveMQ queue

ActiveMQ queue 2

ActiveMQ queue 3

When you are interested in learning how to consume an ActiveMQ message then you realy need to read the following “how to”: how to use a mediation route to read messages from ActiveMQ

 

One Comment

Leave a Reply