One Star

Reading java or protobuf object

I have a senario where I recieve real time java or protobuf objects. I need to extract data from those object and store into database. Is there a way in Talend where I can take java object as input and extract fields of that object.
20 REPLIES
Community Manager

Re: Reading java or protobuf object

Hello
There is no component can extract records from an Java object directly, you have to hard code and create an routine to do that, and then call the routine on tJavaRow, for example:
input flow----tJavaRow--tMysqlOutput
on tJavaRow:
output_row.id=RoutineName.getID(input_row.Java object column);

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Reading java or protobuf object

What should be content of routine? The method getID which you have specified takes object property and returns string. But how we will take object as input flow.
Community Manager

Re: Reading java or protobuf object

Hello
What should be content of routine? The method getID which you have specified takes object property and returns string. But how we will take object as input flow.

It is just my thinking, where does your java ojbect come from and what data do you want to extract?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Reading java or protobuf object

I have created a routine which will read java object and Using reflection I get values of all the fields of object in the form
id,name,age,course
2,ss,14,science
as one string.
Now I want to use this routine as input so that I can use it in my application which keep on getting object and they are converted into string and we can perform transformation on that data.
How can I use this routine as input or how to create component from that routine.
If require that piece of code I can paste it.
One Star

Re: Reading java or protobuf object

You can use a tfixedflowinput, to read your string, and with a tmap, you can split it in the schema :id,name,age,course
One Star

Re: Reading java or protobuf object

how to make my java routine as input flow in talend.
One Star

Re: Reading java or protobuf object

Can I make my java routine as component. How can I create my own component
One Star

Re: Reading java or protobuf object

Please help me. If you want I can send you my java program. i want to use that java program as input
Community Manager

Re: Reading java or protobuf object

Hello
What's the return type of your routine? You can call the routine on tfixedFlowInput, set the value as:
RoutineName.Methodname(parameters)
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Reading java or protobuf object

routine returns string. How to use my routine in tFixedFlowInput.
my Routine is --
public class ReadObject {

public static String getString(Object obj) {
String str=objectToString(obj);
return str;
}
public static String objectToString(Object obj)
{
StringBuilder result = new StringBuilder();
StringBuilder result1 = new StringBuilder();

Field[] fields = obj.getClass().getDeclaredFields();
//print field names paired with their values
for ( Field field : fields ) {
try {
result.append( field.getName() );
result.append(",");
//requires access to private field:
field.setAccessible(true);
result1.append( field.get(obj) );
result1.append(",");
}
catch ( IllegalAccessException ex ) {
System.out.println(ex);
}

}
result.append("\n");
result.append(result1);
return result.toString();
}
}
Community Manager

Re: Reading java or protobuf object

Hello
Please see my screenshot.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Reading java or protobuf object

I want to use this code outside talend in my eclipse which will call this piece of code to pass object.how can I use this code outside talend.
Community Manager

Re: Reading java or protobuf object

Hello
You can write this piece of code in Eclipse and pass the return string to talend job. See
5932
5658
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Reading java or protobuf object

Shong Thx for your valuable help. It really helped me. I want to know one more thing in tFixedflowInput we specify value as routine method. but i want to ReadObject.getString(new Person("shaky", "15")); should get object from outside talend. In eclipse I should also able to pass object to getString() method
Community Manager

Re: Reading java or protobuf object

Hello
ReadObject.getString(new Person("shaky", "15")); should get object from outside talend. In eclipse I should also able to pass object to getString() method

Why don't you write getString() method in eclipse and call it in eclipse, return a string and pass string to talend job?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Reading java or protobuf object

In my design, i get real time object from various networks. I have to pass these object directly to talend job which will perform ETL. That is why I was trying to take java object as input to the talend job. It should be talend job to extract data from object. I need solution around this.
Community Manager

Re: Reading java or protobuf object

Hello
I want to use this code outside talend in my eclipse which will call this piece of code to pass object.how can I use this code outside talend.

But you said that you want to call this piece of code in Eclipse, outside Talend.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Reading java or protobuf object

ya, so that I can pass my objects to this talend thorugh another application.
One Star

Re: Reading java or protobuf object

I failed to find any solution to pass java object to talend input from outside. Please give me some solution for this. Or for time being how can I pass string to talend input from outside Talend.
Community Manager

Re: Reading java or protobuf object

Hello
Or for time being how can I pass string to talend input from outside Talend.

Here is an example showing how to pass variables to talend job in Eclipse.
1)Create a job in Talend, see pic1-2.
2)See topics to know how to export the job from Talend, deploy the job into Eclipse and create a test class in Eclipse.
2901
5932
3)The job use context vars, so we also import the Default.properties file into Eclipse. see pic3-4.
4)Call the talend job in Eclipse. see pic 5
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business