How can a properties file be created using Talend

2019-02-15 17:41发布

问题:

I've used Talend Open Integration studio for sometime to just create jobs and run it from the IDE or export it as executable jar file. But I haven't used it extensively. Is it possible to create an external configuration file that holds different server names and other variables so that after I create an executable jar file of my Talend job, I can just change configuration text file and select different database servers or port options?

I also used MuleSoft for a little bit, so if anyone knows how to do this with MuleSoft any advise would be kindly appreciated.

回答1:

From the content of your question, I would rephrase the subject "How can an external properties file be read and used in a Talend Open Studio Data Integration job?"

First... create your properties file, "common.properties". You could put it in (for example) /etc/classpath, or c:\etc\classpath

Example content for property file

example_property="This is an example property"

Create a common context in the Talend Project and add the same properties to the context

Create a re-usable job to read the properties and load them. Let's call it Read_ Properties.

Use a tFileInputDelimited component to read the props file. It should use "=" as the row separator.

It should have a schema with two columns

key, string 
value, string

The output should go to a tBufferOutput

Now... save that reusable job.

Create a new job, example_calling_job.
That job should should use the Common context. That job should have a prejob step, call the properties job with tRunJob, send row output to a tContextLoad

Then, your component in the example_calling_job can use the context variables which were loaded by the property reader job.

Run the example_calling_job. The tJava component writes out the context.example_property value, which was loaded by the property reader job into the context variable.

Starting job example_calling_job at 11:35 02/03/2016.

[statistics] connecting to socket on port 3497
[statistics] connected
This is an example property.
[statistics] disconnected
Job example_calling_job ended at 11:35 02/03/2016. [exit code=0]


回答2:

With Talend, you define your parameters in a Context. You can init a Context with the component tContextLoad ( https://help.talend.com/display/TalendComponentsReferenceGuide54EN/tContextLoad ). If you are using a standalone job then you can set or override a context value with the command line argument --context_param.



回答3:

You can use tFileOutputProperties to crteate properties file. Specify the file path of the .properties file in the component settings.

Note that the input schema of the tFileOutputProperties should have only two fields - key and value.

Similarly, to read from a .properties file, use tFileInputProperties