Interface RatpackConsulConfig


  • public interface RatpackConsulConfig
    Integration for retrieving values from a Consul Key-Value store as ByteSource to be used with the existing ServerConfigBuilder parsing options.
    Since:
    1.5
    • Method Summary

      Static Methods 
      Modifier and Type Method Description
      static com.google.common.io.ByteSource value​(String key)
      Read the specified key as a ByteSource using the default Consul agent connection properties.
      static com.google.common.io.ByteSource value​(String key, com.orbitz.consul.option.QueryOptions queryOptions)
      Read the specified key as a ByteSource using the default Consul agent connection properties and the provided QueryOptions.
      static com.google.common.io.ByteSource value​(String key, com.orbitz.consul.option.QueryOptions queryOptions, Action<? super com.orbitz.consul.Consul.Builder> clientConfig)
      Read the specified key as a ByteSource using the specified configuration to connection to Consul and the provided QueryOptions.
      static com.google.common.io.ByteSource value​(String key, Action<? super com.orbitz.consul.Consul.Builder> clientConfig)
      Read the specified key as a ByteSource using the specified configuration to connection to Consul.
    • Method Detail

      • value

        static com.google.common.io.ByteSource value​(String key)
        Read the specified key as a ByteSource using the default Consul agent connection properties.
        Parameters:
        key - the key to read from Consul's Key-Value store
        Returns:
        a ByteSource representing the value stored in the key
        See Also:
        value(String, QueryOptions, Action)
      • value

        static com.google.common.io.ByteSource value​(String key,
                                                     com.orbitz.consul.option.QueryOptions queryOptions)
        Read the specified key as a ByteSource using the default Consul agent connection properties and the provided QueryOptions.
        Parameters:
        key - the key to read from Consul Key-Value store
        queryOptions - the options to use when querying Consul
        Returns:
        a ByteSource representing the value stored in the key
        See Also:
        value(String, QueryOptions, Action)
      • value

        static com.google.common.io.ByteSource value​(String key,
                                                     Action<? super com.orbitz.consul.Consul.Builder> clientConfig)
        Read the specified key as a ByteSource using the specified configuration to connection to Consul.
        Parameters:
        key - the key to read from Consul's KeyValue store
        clientConfig - the configuration for the Consul connection
        Returns:
        a ByteSource representing the value stored in the key
        See Also:
        value(String, QueryOptions, Action)
      • value

        static com.google.common.io.ByteSource value​(String key,
                                                     com.orbitz.consul.option.QueryOptions queryOptions,
                                                     Action<? super com.orbitz.consul.Consul.Builder> clientConfig)
        Read the specified key as a ByteSource using the specified configuration to connection to Consul and the provided QueryOptions. The returned value can then be passed to the existing parsing options in ServerConfigBuilder to provide configuration.

        
         import ratpack.consul.RatpackConsulConfig;
         import ratpack.test.embed.EmbeddedApp;
         import com.orbitz.consul.option.ImmutableQueryOptions;
        
         public class Example {
           public static class Config {
             public String name;
             public String environment;
             public String secret;
           }
        
           public static void main(String... args) throws Exception {
             EmbeddedApp.of(a -> a
               .serverConfig(s -> s
                 .yaml(RatpackConsulConfig.value("default/app"))
                 .json(RatpackConsulConfig.value("default/environment", ImmutableQueryOptions.builder().token("app-acl-token").build()))
                 .props(RatpackConsulConfig.value("app/environment", b -> b.withUrl("https://consul.domain.io")))
                 .require("/config", Config.class)
               )
               .handlers(c -> c
                 .get(ctx -> ctx.render(ctx.get(Config.class)))
               )
             );
           }
         }
         
        Parameters:
        key - the key to read from Consul Key-Value store
        queryOptions - the options to use when querying Consul
        clientConfig - he configuration for the Consul connection
        Returns:
        a ByteSource representing the value stored in the key