Skip to content

real-comp/consul-kv-jaxrs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

consul-kv-jaxrs

A minimalistic Java client for the Consul Key/Value HTTP API

Consul is fantastic. One nice feature of Consul is it's Key/Value store that is exposed with an HTTP API.

This consul-kv-jaxrs client exposes only the Key/Value features of Consul via a JAX-RS client. If you need access to the full functionality of the Consul HTTP API, this library is not for you. There are already several Java Consul clients. Here are two:

Example

ConsulKeyValue consul = new ConsulKeyValue("http://my-consul-server.com");
Optional<String> value = consul.get("foo");    
consul.put("foo", "bar");    
consul.remove("foo");    
Set<String> keys = consul.keySet();

You can also provide your own JAX-RS client if needed.
We use this to access a HA Consul server protected by HTTP BASIC auth from DropWizard services.

//Authenticator is a simple JAX-RS ClientRequestFilter for BASIC HTTP Auth. 
Client jaxrs = ClientBuilder.newBuilder().register(new Authenticator("username","password")).build();
ConsulKeyValue consul = new ConsulKeyValue("http://my-consul-server.com", jaxrs);

If you are not storing String values, there is also a RawConsulKeyValue class that leaves the JSON parsing and Base64 decoding up to you.

Any unexpected response is packaged as an IOException.

Dependencies

  • Java 8
  • JAX-RS 2.0.1 Client
  • Jackson 2.8.7

Maven

<dependency>
    <groupId>com.real-comp</groupId>
    <artifactId>consul-kv-jaxrs</artifactId>
    <version>0.0.2</version>
</dependency>

About

A minimalistic Java client for the Consul Key/Value HTTP API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages