You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "naveen.palle" <na...@gmail.com> on 2015/11/17 07:08:52 UTC

Building Camel Dynamic router getting after properties from Database

Hi,

I am currently working on dynamic camel route builder for each customer. I
am getting customer information form database.  My route : 

public class RouteAllCust extends SpringRouteBuilder{

	
	public String dataSource;
	
	@SuppressWarnings("unchecked")
	@Override
	public void configure() throws Exception {
		
		//Route0
		from("direct:cornExp"+dataSource)
		.to("sql:select * from PropertiesTable where keytext like
'cid.csv.ftp%'?dataSourceRef="+dataSource)
		.process(new CustomerProcessor())
		.split(header("customers"))
			.process(new IndivisualCustomerProcessor())
			.to("quartz://timerName" + "${in.header.cid}" + 
"?${in.header.cornExpression}").routeId("Cron Scheduler Route "+
"${in.header.cid}")
			.to("direct:ftpupload"+dataSource);
	
	}

	public String getDataSource() {
		return dataSource;
	}

	public void setDataSource(String dataSource) {
		this.dataSource = dataSource;
	}
}
 
I have injected dataSource form spring config.

CustomerProcessor : 
public class CustomerProcessor implements Processor {
@Override
	public void process(Exchange exchange) throws Exception {

		logger.info("Getting customer list map");
		List<Map&lt;String, Object>> customerList = (List<Map&lt;String, Object>>)
exchange.getIn().getBody(List.class);
		exchange.getIn().setHeader("customers", customerList);
		logger.info("Customer list size : " + cust.size());

	}
}

IndivisualCustomerProcessor :

public class IndivisualCustomerProcessor implements Processor{

	private static final Logger logger =
LoggerFactory.getLogger(IndivisualCustomerProcessor.class);
	@Override
	public void process(Exchange exchange) throws Exception {
		
		//logger.info("Getting Indivisual Customer ");
		
		Customer c = (Customer) exchange.getIn().getBody(Customer.class);
		if(c.getcId() != null)	{
			Map<String, Object> headerMap = new HashMap<String, Object>();
			headerMap.put("cid", c.getcId());
			headerMap.put("ccode", c.getCustomerCode());
			headerMap.put("username",c.getUserName());
			headerMap.put("password",c.getPassword());
			headerMap.put("ftphost",c.getFtpHost());
			headerMap.put("reportsubscription", c.getReportSubscription());
			headerMap.put("customerprofile", c.getCustProfile());
			headerMap.put("cornExpression", c.getCustProfile());
					
			exchange.getIn().setHeaders(headerMap);
		}
		else{
			logger.info("Can not process this customer. Customer id is null. " +
c.toString());
		}
		
		logger.info("Processing of Customer id   : " + c.getcId() + " - " +
c.getCustProfile());
		
	}

Where I am setting customer properties in the header. These properties are
used to create route for each customer.


I am getting following error : 

Failed to resolve endpoint:
quartz://timerName$%7Bin.header.cid%7D?%24%7Bin.header.cornExpression%7D=
due to: There are 1 parameters that couldn't be set on the endpoint. Check
the uri if the parameters are spelt correctly and that they are properties
of the endpoint. Unknown parameters=[{${in.header.cornExpression}=}]

I have used header("cornExpression") instead of ${in.header.cornExpression}.
I am getting same error message.

Can anyone help me to fix the issue.

Thank you





--
View this message in context: http://camel.465427.n5.nabble.com/Building-Camel-Dynamic-router-getting-after-properties-from-Database-tp5773968.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Building Camel Dynamic router getting after properties from Database

Posted by "naveen.palle" <na...@gmail.com>.
Thank you for quick response.

Is there anyway to do dynamic route in my case.

Basically I have to create Cron route getting properties from database.

Thank you.
Naveen



--
View this message in context: http://camel.465427.n5.nabble.com/Building-Camel-Dynamic-router-getting-after-properties-from-Database-tp5773968p5774018.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Building Camel Dynamic router getting after properties from Database

Posted by Antonin Stefanutti <an...@stefanutti.fr>.
Expressions are not evaluated where you’ve used them: 

> to("quartz://timerName" + "${in.header.cid}" + "?${in.header.cornExpression}")

> .routeId("Cron Scheduler Route "+"${in.header.cid}")

As documented in http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html

Since Camel 2.16, you can use the Dynamic To DSL as documented in http://camel.apache.org/message-endpoint.html#MessageEndpoint-DynamicTo. Before Camel 2.16, you have to use the simple DSL http://camel.apache.org/simple.html. 

However, there are two specific points worth noting in your examples:
- In the latter statement, that’d mean that your route id changes dynamically per exchange which is not possible / logical.
- The Quartz component does not support producers. You can only write from("quartz").

> On 17 Nov 2015, at 07:08, naveen.palle <na...@gmail.com> wrote:
> 
> Hi,
> 
> I am currently working on dynamic camel route builder for each customer. I
> am getting customer information form database.  My route : 
> 
> public class RouteAllCust extends SpringRouteBuilder{
> 
> 	
> 	public String dataSource;
> 	
> 	@SuppressWarnings("unchecked")
> 	@Override
> 	public void configure() throws Exception {
> 		
> 		//Route0
> 		from("direct:cornExp"+dataSource)
> 		.to("sql:select * from PropertiesTable where keytext like
> 'cid.csv.ftp%'?dataSourceRef="+dataSource)
> 		.process(new CustomerProcessor())
> 		.split(header("customers"))
> 			.process(new IndivisualCustomerProcessor())
> 			.to("quartz://timerName" + "${in.header.cid}" + 
> "?${in.header.cornExpression}").routeId("Cron Scheduler Route "+
> "${in.header.cid}")
> 			.to("direct:ftpupload"+dataSource);
> 	
> 	}
> 
> 	public String getDataSource() {
> 		return dataSource;
> 	}
> 
> 	public void setDataSource(String dataSource) {
> 		this.dataSource = dataSource;
> 	}
> }
> 
> I have injected dataSource form spring config.
> 
> CustomerProcessor : 
> public class CustomerProcessor implements Processor {
> @Override
> 	public void process(Exchange exchange) throws Exception {
> 
> 		logger.info("Getting customer list map");
> 		List<Map&lt;String, Object>> customerList = (List<Map&lt;String, Object>>)
> exchange.getIn().getBody(List.class);
> 		exchange.getIn().setHeader("customers", customerList);
> 		logger.info("Customer list size : " + cust.size());
> 
> 	}
> }
> 
> IndivisualCustomerProcessor :
> 
> public class IndivisualCustomerProcessor implements Processor{
> 
> 	private static final Logger logger =
> LoggerFactory.getLogger(IndivisualCustomerProcessor.class);
> 	@Override
> 	public void process(Exchange exchange) throws Exception {
> 		
> 		//logger.info("Getting Indivisual Customer ");
> 		
> 		Customer c = (Customer) exchange.getIn().getBody(Customer.class);
> 		if(c.getcId() != null)	{
> 			Map<String, Object> headerMap = new HashMap<String, Object>();
> 			headerMap.put("cid", c.getcId());
> 			headerMap.put("ccode", c.getCustomerCode());
> 			headerMap.put("username",c.getUserName());
> 			headerMap.put("password",c.getPassword());
> 			headerMap.put("ftphost",c.getFtpHost());
> 			headerMap.put("reportsubscription", c.getReportSubscription());
> 			headerMap.put("customerprofile", c.getCustProfile());
> 			headerMap.put("cornExpression", c.getCustProfile());
> 					
> 			exchange.getIn().setHeaders(headerMap);
> 		}
> 		else{
> 			logger.info("Can not process this customer. Customer id is null. " +
> c.toString());
> 		}
> 		
> 		logger.info("Processing of Customer id   : " + c.getcId() + " - " +
> c.getCustProfile());
> 		
> 	}
> 
> Where I am setting customer properties in the header. These properties are
> used to create route for each customer.
> 
> 
> I am getting following error : 
> 
> Failed to resolve endpoint:
> quartz://timerName$%7Bin.header.cid%7D?%24%7Bin.header.cornExpression%7D=
> due to: There are 1 parameters that couldn't be set on the endpoint. Check
> the uri if the parameters are spelt correctly and that they are properties
> of the endpoint. Unknown parameters=[{${in.header.cornExpression}=}]
> 
> I have used header("cornExpression") instead of ${in.header.cornExpression}.
> I am getting same error message.
> 
> Can anyone help me to fix the issue.
> 
> Thank you
> 
> 
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Building-Camel-Dynamic-router-getting-after-properties-from-Database-tp5773968.html
> Sent from the Camel - Users mailing list archive at Nabble.com.