How to change the Talend Runtime context of a Route or Job

Contexts are powerful features within Talend ESB. They enable you to parameterise your jobs and routes so that you can run the same code in different environments with little effort. Choosing the context in which to run your Job or Route is easy in Studio. The Talend Runtime context can also be selected in just a few quick commands. Read on to find out how it’s done.

Defining context variables and contexts

Context variables in Talend are variables which may change depending on the environment the Job or Route will be run in. This commonly includes things like:

  • Web service endpoints
  • File and directory paths
  • JMS connection details

These context variables can be grouped into contexts - where each context is a set of context variables which can be used at runtime. These are useful when you want to deploy the same job or service into (e.g.) three different environments - development, test and production - and not have to worry about making three different versions of the same Job.

To add context variables in Talend Studio, see the manual chapter How to define context variables for a Job.

Running a Job or Route in Talend Studio under a specific context is simply a matter of selecting the correct context from the dropdown list in the Run window. When moving your component to Talend Runtime, you need to take a few extra steps to make sure you’re running the job in the correct Talend Runtime context.

Moving to Runtime

In other (non-ESB) editions of Talend, you can specify a context for a Job by passing the context name as a command line argument, when you run the Job.

But in Talend ESB, Jobs and Routes aren’t run from the command line; instead they are deployed into a container (Apache Karaf/Talend Runtime). This means that the container manages the context instead. So, to change the context - or environment - for a given job, you need to do this through the Runtime.

The steps below describe how to set the Talend Runtime context of a Job or Route once it has been deployed.


How to change the Talend Runtime context

Once you have deployed your job or route, follow these steps to change the context at runtime:

  1. Start a new Karaf (Talend Runtime) console session - either by running trun.bat/.sh, or client.bat/.sh, depending on how you run Talend Runtime in your environment.

  2. Type config:edit <your-job-name>, e.g. config:edit MyJob

  3. Type config:property-set context <context-name>
    NB: If you’re using a version of Talend prior to v6.0, you should instead use config:propset context <context-name>.

  4. Type config:update to apply the change.

  5. Type list to show all the components deployed into your Runtime. Look for the bundle ID by the side of the bundle you’ve just changed the context for. You will need this in the next step.

  6. To see the changes take effect, you need to refresh your Job or Route. To do this, type refresh <bundle-id>, e.g. refresh 403

Example

In the screenshot below, see how I first use the output of the list command to find the bundle ID of my component, JobWithContexts, which is 239.

Then I use the config:edit, and property-set commands to change my context to test (my Job has three contexts, dev, test and prod). Then I refresh the bundle, and the changes take effect.


If this post has helped you manage your jobs and routes in Talend Runtime, please share it! You can also post your feedback and questions in the comments below.