Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

readme.md

REST client plugin for Microserver

micro-client example apps

This plugin provides thre REST Clients

  1. NIORestClient - which is a non-blocking REST client using NIO, wrapper over Apache Async HTTP. Modified to return Java 8 CompletableFuture objects.
  2. AsyncRestClient - a wrapper over the Async Jersey Rest Client (it is asyncrhonous, but makes use of threads rather than NIO). Modified to return Java 8 CompletableFuture objects, and enhanced with withXXXX methods for configuration purposes.
  3. RestClient - which syncrhonous wrapper over the Jersey Rest Client, enhanced with withXXXX methods for configuration purposes

The NIORestClient is available as Spring bean. AsyncRestClient & RestClient can simply be instantiated via the new keyword.

Example AsyncRestClient

public class Example{


   private final int readTimeout = 10_000;
   private final int connnectionTimeout = 1_000;
   private final AsyncRestClient<Result> restClient = new AsyncRestClient<>(readTimeout,connectionTimeout);;
   private final String url;
   private final String ACCEPT_HEADERS;
   private final String CONTENT_HEADERS;

   public CompletableFuture<Result> query(Payload payload){
   	
   	return this.restClient.withAccept(ACCEPT_HEADERS)
   					.withContentType(CONTENT_HEADERS)
   					.withResponse(RESULT.class)
   					.post(url,payload);
   
   }

   
}

Example RestClient

public class Example{


   private final int readTimeout = 10_000;
   private final int connnectionTimeout = 1_000;
   private final RestClient<Result> restClient = new RestClient<>(readTimeout,connectionTimeout);
   private final String url;
   private final String ACCEPT_HEADERS;
   private final String CONTENT_HEADERS;

   public Result query(Payload payload){
   	
   	return this.restClient.withAccept(ACCEPT_HEADERS)
   					.withContentType(CONTENT_HEADERS)
   					.withResponse(RESULT.class)
   					.post(url,payload);
   
   }

   
}

Configuring the NIORestClient

The following properties & defaults are available to set values on the underlying Apache Async Http Client.

Set the timeout in milliseconds used when requesting a connection from the connection manager using the underlying HttpClient. A timeout value of 0 specifies an infinite timeout.

nio.rest.connection.request.timeout=10000

Set the socket read timeout for the underlying HttpClient in millis. A timeout value of 0 specifies an infinite timeout.

nio.rest.connection.read.timeout=0

The connection timeout for the underlying HttpClient in millis. A timeout value of 0 specifies an infinite timeout.

nio.rest.connection.connect.timeout:2000

To use

Maven Central

Simply add to the classpath

Maven

 <dependency>
    <groupId>com.aol.microservices</groupId>  
    <artifactId>micro-client</artifactId>
    <version>x.yz</version>
 </dependency>

Gradle

compile 'com.aol.microservices:micro-client:x.yz'