Asynchronous Spring REST call for Work Executor Sample

ساخت وبلاگ

Vote count: 0

I am developing work executor software. So far this is designed in the following way:

  1. Client will invoke on URL which will call on a Spring REST controller method
  2. The REST controller gets a bean "WorkAcceptor" which is configured as "prototype".
  3. The class "WorkAcceptor" creates a bean object called "WorkQInserter" and pass the request to "enqueueTasks()" of "WorkQInserter". After calling the enqueueTasks() it sends out generated work id to the client.
  4. The method "enqueueTasks()" is called on the bean object which stores the request in Oracle AQ
  5. A single background thread "WorkExecutor" continuosly runs which pops out request from the AQ and forwards the request to another singleton object "WorkExecutor" for processing
  6. The "WorkExecutor" executes the work as reuested and stores the result in Oracle DB and it requires roughly 30-40 secs to complete the process

Note that the WorkExecutor gets request from FIFO Q and executes the same and stores in DB. The client has to check the status of the work later (with the reference workid received at step # 3) by calling on a different REST (for retrieve work status).

I have almost nil knowledge in asynchronous method call. I want to know what changes have to do to the REST controller in #1 or any other associated classes to make the REST call asynchronous? Such that the client calls on the REST asynchronously, get accepted response, request pushed in AQ, "WorkExecutor" pops out request from AQ and executes work, stores in DB and callback success/failure on the client.

Please observe my code snippets. The beans are configured in spring configuration bean xml file.

Any idea with some sample will be highly appreciated. Thanks in advance and forgive me for the long post.

REST controller

@RestController public class WorkExecutorRESTController {

@RequestMapping(value = "/workexecutor/{workdetails}", method = RequestMethod.GET)
public ResponseEntity<Integer> executeWork( @PathVariable String workdetails )
{ WorkAcceptor l_WorkAcceptor = WorkerBeanFactory.getBeanForId("WorkAcceptor"); //configured as prototype bean Integer result = l_WorkAcceptor.sendWork(workdetails); retu new ResponseEntity<Integer>(result,HttpStatus.OK);
}

WorkAcceptor class

public class WorkAcceptor {

public Integer sendWork(String workdetails)
{ WorkQInserter l_WorkQInserter = WorkerBeanFactory.getBeanForId("WorkQInserter"); //configured as prototype bean // Here generate the work id if(l_WorkQInserter.enqueueTasks(workdetails, workid) == SUCCESSFUL) { retu workid; //this goes back to client as reference id } else retu -1;
}

}

WorkQInserter class

public class WorkQInserter {

public Integer WorkQInserter(String workdetails, Integer workid)
{ //PUSH THE DATA IN ORACLE AQ //RETURN SUCCESS OR FAILURE
}

}

WorkExecutor class

//This class is configured as singleton in bean xml. During initialization it runs a dedicated thread //which periodically pops out request from the AQ and process

public class WorkExecutor {

public Integer execute()
{ //POPS OUT THE REQUEST FROM ORACLE AQ //EXECUTE WORK //RETURN SUCCESS OR FAILURE
}

}

asked 23 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 318 تاريخ : سه شنبه 5 مرداد 1395 ساعت: 14:37