Altering default HTTP client configuration
The above example sets of readTimeout
property of the class.
If you wish to have a separate configuration per client then there a couple of options. You can configure Service Discovery manually in application.yml
and apply per-client configuration:
Manually configuring HTTP services
micronaut:
http:
services:
urls:
- http://foo1
- http://foo2
Then simply inject the named client configuration:
Injecting an HTTP client
You can also simply define a bean that extends from and ensuring that the javax.inject.Named
annotation is used to name it appropriately:
Defining an HTTP client configuration bean
@Named("twitter")
@Singleton
public TwitterHttpClientConfiguration(ApplicationConfiguration applicationConfiguration) {
super(applicationConfiguration);
}
Injecting an HTTP client
Alternatively if you are not using service discovery then you can use the configuration
member of @Client
to refer to a specific type:
Injecting an HTTP client
@Client(value="https://api.twitter.com/1.1",
configuration=TwitterHttpClientConfiguration.class)
RxHttpClient httpClient;
If you have a client that needs to handle a significant number of requests then you can benefit from enabling HTTP client connection pooling. The following configuration will enable pooling for the client:
1 | Enables the pool |
2 | Sets the maximum number of connections in the pool |
See the API for ConnectionPoolConfiguration for details on available options to configure the pool.