Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send multiple response for a request using java

I am attempting to send multiple responses at certain interval of time for a http-request from client.I am using Spring Boot RESTful web serives which receives a request from AngularJs client. RESTFul web services will get list of jobs from client, i need to send response to the client after the completion of each Job.

@PostMapping("/runExecution")
public Object sendingMultipleResponse(String input){

  for(Object obj : ListOfJobs){
    //performs business logic
    return object;
  }

}

Consider 10 Jobs are there in the lists, i need to return the results to the request after the execution of each job. NOTE: For a single request from AngularJs, i need to send multiple responses

like image 378
Dhakshina Moorthy Avatar asked Sep 15 '25 00:09

Dhakshina Moorthy


1 Answers

You can use WebSocket for your scenario. WebSocket provides full duplex communication channel between a server and client. When client sends message (let say request in this case) on server, server will start processing the message and server will respond to the client with the response message (it will be response) like sending status of the message being processed or status of the job that has been triggered by the message sent over the WebSocket. Please refer link

like image 50
mcacorner Avatar answered Sep 16 '25 13:09

mcacorner