Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search

Adding camel consumer routes dynamically to camel context


In this article we are going to learn how to add consumer routes dynamically. Consider a situation where your requirement is to process some files from different FTP servers. And details of those FTP servers keeps changing.

Use Case:

Lets assume you want to achieve something below:

1. Process should be started itself in timely manner.

2. Fetch the FTP server details from the database.

3. Add the camel consumer routes for above FTP servers.

How To DO

Step#1 and Step#2 already explained in other articles so we will mainly focus on step#3 i.e. how to add consumer routes dynamically, if we have SDT data FTPDetails pre-populated.


POJO which will iterate ftpDetails object and add routes:

package com.test;
import java.util.ArrayList;
import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultCamelContext;
import org.eclipse.stardust.common.config.Parameters;
import org.eclipse.stardust.engine.extensions.camel.RouteHelper;
import org.springframework.context.ApplicationContext;
public class CustodianRoutesHelper {
	private static final String PRP_APPLICATION_CONTEXT = "org.eclipse.stardust.engine.api.spring.applicationContext";
	private ApplicationContext springContext;
	private CamelContext camelContext;
	public CustodianRoutesHelper() {
		this.springContext = (AbstractApplicationContext) Parameters.instance()
		this.camelContext = (DefaultCamelContext) this.springContext
	public void addFtpRoutes(Object ftpDetails) {
		Map<String, Object> map = (Map<String, Object>) ftpDetails;
		ArrayList<Map> ftpDetailsList = (ArrayList<Map>) map.get("FtpDetails");
		for (int i = 0; i < ftpDetailsList.size(); i++) {
			Map<String, String> ftpRecord = ftpDetailsList.get(i);
			StringBuilder routeDefinition = new StringBuilder(
					"<routes xmlns=\"\" xmlns:xsi=\"\">"
							+ "<route id=\"CustodianFTPConsumer"
							+ i
							+ "\""
							+ " autoStartup=\"false\""
							+ ">"
							+ "<description>This is Cutodian Route listening to FTP Server: "
							+ ftpRecord.get("FTPHostName")
							+ "</description>"
							+ "<from uri=\"ftp://");
			routeDefinition.append(ftpRecord.get("FTPUserName") + "@"
					+ ftpRecord.get("FTPHostName") + ":"
					+ ftpRecord.get("FTPPortNo") + "/"
					+ ftpRecord.get("FTPSourceDir") + "?" + "password="
					+ ftpRecord.get("FTPPassword")
					+ "&amp;delay=1000&amp;delete=true&amp;disconnect=true\""
					+ "/>");
					.append("<to uri=\"ipp:authenticate:setCurrent?user=motu&amp;password=motu\"/>");
					.append("<to uri=\"ipp:process:start?processId=FTPProcess\"/>");
					.append("<to uri=\"ipp:authenticate:removeCurrent\"/>");
			try {
				System.out.println("Adding below route definition to bean: "
						+ routeDefinition);
			} catch (Exception e) {
				// TODO Auto-generated catch block

Deploy the attached model and artifacts and run the process


Routes will be listed under Admin-->Integration-runtime from there you can start and stop the routes.



All the artifacts dicussed in this article could be found here

Back to the top