I'm trying to build a Mulesoft custom connector which makes HTTP requests to a third-party system, and I'd like these HTTP requests to be made in a non-blocking manner such that execution can continue without waiting on the HTTP response to be returned.
There is an example of this in the Mulesoft documentation here which shows this example code:
public void request(String url, @Connection HttpClient client, @Content String body,
CompletionCallback<InputStream, HttpAttributes> callback ) {
client.send(url, body, new HttpResponseCallback() {
void onResponse(HttpResponse response) {
callback.success(Result.<InputStream, HttpAttributes>builder()
.output(response.getBody())
.attributes(toAttributes(response))
.build());
}
void onError(Exception e) {
callback.error(e);
}
});
}
It also states that non-blocking behaviour can be provided
by an HttpClient that supports asynchronous responses
Mulesoft's custom connector documentation states
The HttpClient is capable of using non-blocking I/O to make the requests.
but I don't understand how!
The example code above calls a method send(String, String, HttpResponseCallback)
from the HttpClient
interface. However, the HttpClient
interface, as documented in Mulesoft's API javadoc does not have such a method.
I see that the HttpClient
interface does have sendAsync(HttpRequest request)
methods, but I'm failing to understand how that could be used with the example code.
I understand that Mulesoft's HttpClient
is implemented using Project Grizzly's HTTP client, and that supports non-blocking requests, so I feel this is possible to do, I just don't understand how...
Thanks for any tips!