I have a spring boot application, it has a rest controller that returns strings and text files. I want to monitor server-side download progress and send messages to the queue.
When working with HttpServletI just got OutputStreamfrom the object HttpResponseand pushed bytes on the socket, calculating the progress as they appeared:
byte[] buffer = new byte[10];
int bytesRead = -1;
double totalBytes = 0d;
double fileSize = file.length();
while ((bytesRead = inStream.read(buffer)) != -1) {
outStream.write(buffer, 0, bytesRead);
totalBytes += bytesRead;
queueClient.sendMessage(
"job: " + job + "; percent complete: " + ((int) (totalBytes / fileSize) * 100));
}
However, with spring boot, since a lot of things happen under the hood, I'm not 100% sure how to approach it.
I just started with spring boot, so it's easy on me! My Controllernow looks like this:
@RestController
@RequestMapping("/api/v1/")
public class MyController {
@Autowired
QueueClient queue;
@RequestMapping(value = "info/{id}", method = RequestMethod.GET)
public String get(@PathVariable long id) {
queue.sendMessage("Client requested id: " + id);
return "You requested ID: " + id;
}
@RequestMapping(value = "files/{job}", method = RequestMethod.GET)
public String getfiles(@PathVariable long job) {
queue.sendMessage("Client requested files for job: " + job);
return "You requested files for job " + job;
}
}
, . spring REST Controller s?
HttpResponse, ?