I am trying to build a spring integration based architecture where my system needs to talk to different other systems over a variety of protocols. One of these systems is based on exposes REST endpoint for long-running jobs.
I want to have a Spring Integration HTTP outbound component that will submit a job (say on POST /api/job/submit
with a requestId
) and then poll the result of the job from a different endpoint (say GET /api/job/{request-id}/result
).
[Note: that the job will be long running and the result may not be immediately available]
I am trying to expose this functionality from submitting a job to getting a result using a single function that will return a Future
containing the result of the job.
This is what I am thinking:
public Future<JobResult> executeJob(JobInput input) {
// call the job submission endpoint using Http Outbound component or RestTemplate
// get the result of this submission and confirm it is Http 200
// using the request id, kick off the task of checking the job result to an executor service. (instance of JobChecker)
// return the future from the submitted callable.
}
class JobChecker implements Callable<JobResult> {
@Override
public JobResult call() throws Exception {
while(true) {
// using rest template or another HTTP outbound channel check if the result of requestId is available
}
}
}
What components/combination of components from Spring Integration should I be using to achieve this? Am I missing something in terms of hardening this to a production grade solution viz. catering to error handling, routing, guaranteed delivery and idempotency of operation?