Passing stream to job as parameter

explorer

Is there a way to pass a stream while launching the job through job Launcher, something similar to passing jobParameters?

I have a separate service for getting file and then I want to initiate the batch job to load it.

Code scenario :

Consider this sample. Here job is defined but actual launcher resides in the dependency underneath.

So consider in sample, I add a controller which read user's input file and then trigger the sample-job defined in sample which is run by joblauncher.run of underneath.

I was thinking to pass this file stream directly to the job's reader instead of writing it to external disc and reading in Reader's setSeResource

Thrax

After looking at the sample code you provided, I think you could do something like this :

1) Declare a static HashMap in the SimpleJobConfiguration class.

public static Map<String, Object> customStorage = new HashMap<String, Object>();

2) Populate this map from your service

SimpleJobConfiguration.customStorage.put("key", yourStream);

3) Use this static map in the setResource method of your ItemReader (as said in your previous question)

@Override
public void setResource(Resource resource) {

    // Get your stream from the static map
    Byte[] stream = (Byte[]) SimpleJobConfiguration.customStorage.get("key");

    // Convert byte array to input stream
    InputStream is = new ByteArrayInputStream(stream);

    // Create springbatch input stream resource
    InputStreamResource res = new InputStreamResource(is);

    // Set resource
    super.setResource(res);
}

This solution will only work if your service is next to your jobLauncher.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to implement passing of parameter to a StreamedPipeline that uses Action<Stream,Stream>

From Dev

How to use git branch name of Jenkins JOB A in lower stream job B as a parameter to checkout the git branch?

From Dev

Run exe from SQL agent Job cmdexec passing parameter todays date and date -52 weeks

From Dev

Powershell passing variables to a job

From Dev

Passing parameters to a PowerShell job

From Dev

Passing the output of a job in Jenkins to another job

From Dev

Passing string to input stream

From Dev

Passing an array to Get-Job

From Dev

Passing values to job executor pentaho

From Dev

Passing Generated Value to Downstream Job

From Dev

Capture Verbose Stream from Job

From Dev

Passing property as parameter

From Dev

Passing a predicate that was passed in as a parameter

From Dev

GraphQL - passing an ObjectType a parameter

From Dev

Passing a parameter to a linq predicate

From Dev

Passing method as parameter in PHP

From Dev

Passing a class as function parameter

From Dev

Python :: passing a list as parameter

From Java

Passing a method reference as parameter

From Dev

Passing parameter to open view

From Dev

parameter passing mechanism in R

From Dev

Passing property type as parameter

From Dev

WebSQL passing values in as parameter

From Dev

Error passing ContainerInterface as a parameter

From Dev

Passing callback function as parameter

From Dev

Passing parameter to Fragment

From Dev

Passing Null Integer as Parameter

From Dev

Passing alias as parameter

From Dev

Android: passing WeakReference as a parameter