简体   繁体   中英

Triggering a Spring Integration Outbound Adapter after a Spring Batch Job

My requirement is almost same as its described in the post here. ie, triggering a Spring Integration program after a file generator Spring Batch is done. I am primarily using the Spring Integration samples here: XML Configuration and the Test . What I observe is that the Test program initializes the configuration file as ClassPathXmlApplicationContext, then sets some values as required. Ignoring the configuration, the crux of the program seems to be the below four lines:

final File file = new File(sourceFileName);
final Message<File> message = MessageBuilder.withPayload(file).build();
final MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
inputChannel.send(message);

I would like to know if there is an option to move this into the configuration file itself, so I don't have to create a Message or pass it to a MessageChannel from a the test program but can just start the Spring batch and watch it call the Outbound SFTP trigger after the job is complete. If this is done my job is mostly done so that I can just plug it as the next step in the Spring Batch job.

If you note the examples for Inbound Adapter I am able to do all of this in the config file itself with the below lines of code:

<int-sftp:inbound-channel-adapter id="sftpInbondAdapter"
        channel="receiveChannel"
        session-factory="sftpSessionFactory"
        local-directory="file:${inbound.local.directory}"
        remote-directory="${inbound.remote.directory}"
        auto-create-local-directory="true"
        delete-remote-files="false"
        filename-pattern="*.*">
    <int:poller max-messages-per-poll="-1" fixed-rate="1000" />
</int-sftp:inbound-channel-adapter>

<int:channel id="receiveChannel">
    <int:queue/>
</int:channel>

and from the test program I can do as below:

PollableChannel localFileChannel = context.getBean("inboundFileChannel", PollableChannel.class);
System.out.println("Received first file message: " + localFileChannel.receive());

May be I am missing something very fundamental here. I also looked at the sample cited here in the earlier post which is calling a Tasklet and in the Tasklet again the user is initializing the context file which does not seem to be a good approach in my case because I am going to have my Spring Batch and Spring Integration configurations in the same XML as it looks like a cyclic call.

You can use a Messaging Gateway . Just define a POJI and and configure it as a <gateway/> in the same context as your batch job. Inject it into a tasklet step and it will invoke the flow.

Or, use a JobLaunchingGateway to launch your batch job and then do the sftp work after the gateway completes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM