Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><em>I have a problem where in I need to receive a series of messages from an MQ queue and write this to a file and initiate a spring batch job with the file as input</em></li> </ul> <p>One way to do that would be engage a bit of Spring Integration, where you would have a file poller, that would poll for a new file:</p> <pre><code>&lt;file:inbound-channel-adapter id="filePoller" channel="filesAreComing" directory="file:${input.directory}" filename-pattern="test*" /&gt; </code></pre> <p>Adapt a <code>file message</code> ( java.io.File ) to a <code>file name</code> ( String ), since that is what Spring Batch needs. This can be done with a JobLauncher adapter, that is already available from Spring Batch Admin <a href="https://src.springframework.org/svn/spring-batch-admin/trunk/spring-batch-admin-manager/src/main/java/org/springframework/batch/admin/integration/FileToJobLaunchRequestAdapter.java" rel="noreferrer">here</a>:</p> <pre><code>@ServiceActivator public JobLaunchRequest adapt(File file) throws NoSuchJobException { JobParameters jobParameters = new JobParametersBuilder().addString( "input.file", file.getAbsolutePath()).toJobParameters(); return new JobLaunchRequest(job, jobParameters); } </code></pre> <p>wrap it to a <code>JobLaunchRequest</code> ( which is just a holder for a <code>Job</code> and <code>JobParameters</code> ) and send this request [as a message] to <code>JobLaunchingMessageHandler</code>:</p> <pre><code>&lt;service-activator input-channel="jobLauncher"&gt; &lt;beans:bean class="org.springframework.batch.integration.launch.JobLaunchingMessageHandler"&gt; &lt;beans:constructor-arg ref="jobLauncher" /&gt; &lt;/beans:bean&gt; &lt;/service-activator&gt; </code></pre> <p>that would launch the job.</p> <p><em>"input.file" is a parameter that is bound at runtime ( hence #{...} ):</em></p> <pre><code>&lt;bean id="reader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"&gt; &lt;property name="resource" value="#{jobParameters[input.file]}" /&gt; ... line mapper and other props &lt;/bean&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload