I want to return content to users on a rest call, and I want to send a rest call to a tracking server about that content request. If the tracking server gets overwhelmed by too many responses, I don't care if it fails. I want it to timeout quickly and not hold up the main content request. To this end I have created the following:
@Configuration
@EnableAsync
public class AsyncConfiguration {
@Bean (name = "taskExecutor")
public Executor taskExecutor() {
log.info("Creating Async Task Executor");
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setMaxPoolSize(2);//higher in prod
executor.setQueueCapacity(2);//higher in prod
executor.initialize();
executor.setThreadNamePrefix("AyncThread-");
return executor;
}
}
...
@Async
public void trackSearch(TrackingRequest request) {
try {
restTemplate.postForLocation(activityUri, request);
}
catch (Exception e) {
log.info("Exception in tracking activity: " + e.getMessage());
}
}
So, after getting the main content, I call trackSearch
above. I don't care if it fails like I said. But when I'm testing this code in JMeter, I cannot seem to 'beat' the queue size. What I was expecting is that if there are too many users hitting this same end point, that the queue just fills up and it stops trying to call the trackSearch and therefore the restTemplate call. Right now, none of the calls fail.
I'm obviously misunderstanding something here, so if anyone can shed some light on what I'm doing wrong, I'd appreciate it.