Camel to Job parameters

Six Stars

Camel to Job parameters

cTalendJob and tRouteInput allow to send Body and Headers from Apache Camel routes to Talend jobs

But Object type can only be pass through "body".  Headers have to be String only.

I checked the cTalendJob Java code on GitHub and it looks like org.apache.camel.Exchange could be sent to Job if there was a method setExchange(org.apache.camel.Exchange exchange) defined in the Job

That would be great

This is a bit like Datasource but for other eager loading objects instances that are loaded at Config time on the Camel route

How can I force this method definition in a Job ?

What are other options to pass objects from route to job ?


Accepted Solutions
Sixteen Stars

Re: Camel to Job parameters


@vharcq wrote:

Yes headers are Object on the Camel side

And yes Job context can be defined as Objects

But when using the Camel Component cTalendJob, you use Camel Headers to send to Talend Job Context variables, the cTalendJob makes toString() operation :-(


You do not need to use Context Variables at all here. Simply use a tRouteInput inside your Talend job, the headers are received automatically by the cTalendJob, and all you need to do is use a bit of Apache Camel Simple Expression Language to extract the data using the tRouteInput. You are certainly not limited to Strings here


All Replies
Sixteen Stars

Re: Camel to Job parameters

That is not actually the case. Headers are of class Object. When you receive your Exchange through the cTalendJob, you use the Camel Simple Language (http://camel.apache.org/simple.html) to retrieve the IN body ("${in.body}") or the OUT body ("${out.body}"). This is a Message (https://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Message.html). If you take a look at the link above you will see that the Headers are stored as Objects with String keys. 

 

I may have misunderstood your problem here, but you should be able to store any class in a header

Six Stars

Re: Camel to Job parameters

Yes headers are Object on the Camel side

And yes Job context can be defined as Objects

But when using the Camel Component cTalendJob, you use Camel Headers to send to Talend Job Context variables, the cTalendJob makes toString() operation :-(

Six Stars

Re: Camel to Job parameters

As a workaround I had to build a "fat" body included the real body and some other object instances

Sixteen Stars

Re: Camel to Job parameters


@vharcq wrote:

Yes headers are Object on the Camel side

And yes Job context can be defined as Objects

But when using the Camel Component cTalendJob, you use Camel Headers to send to Talend Job Context variables, the cTalendJob makes toString() operation :-(


You do not need to use Context Variables at all here. Simply use a tRouteInput inside your Talend job, the headers are received automatically by the cTalendJob, and all you need to do is use a bit of Apache Camel Simple Expression Language to extract the data using the tRouteInput. You are certainly not limited to Strings here

Six Stars

Re: Camel to Job parameters

I actually did use Propagate Header on cTalendJob and use context on Job to retrieve values.

That is where the toString occurs

When I specify header manually in tRouteInput, I can do Objects

Thanks for being stubborn to me :-)

 

Sixteen Stars

Re: Camel to Job parameters

No problem :-) I've been there when you expect something to work in a particular way. I've spent hours, days, trying to figure out ways of doing things using the ESB. When it works, it's awesome, but when you can't find examples and are left with trial and error, it can be REALLY annoying :-)

Six Stars

Re: Camel to Job parameters

Here is the Project export for use by others Heart