Future<MyMessage> response =
camelProducerTemplate.asyncRequestBody(
"http://veryslow.com/esb/service",
"request", MyMessage.class);
...
// Do something else waiting for the HTTP response.
...
try {
handleResponse(response.get());
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
Handling checked exceptions of Future is especially annoying, as Executor Framework is widely used when implementing popular Request-Reply pattern in messaging systems.
Fortunately Guava's Futures utility provides glue code for handling Future#get exceptions. This extremely useful method is called getUnchecked.
import static com.google.common.util.concurrent.Futures.getUnchecked;
...
Future<MyMessage> response =
camelProducerTemplate.asyncRequestBody(
"http://veryslow.com/esb/service",
"request", MyMessage.class);
...
// Do something else waiting for the HTTP response.
...
handleResponse(getUnchecked(response));
Thank you Google.
I love checked exceptions. I'm not kidding.
ReplyDeleteWhat to hell can one love in them? :)
ReplyDelete