All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.discovery.guice.EurekaClientModule Maven / Gradle / Ivy

package com.netflix.discovery.guice;

import com.google.inject.AbstractModule;
import com.google.inject.binder.LinkedBindingBuilder;
import com.google.inject.name.Names;
import com.netflix.appinfo.providers.EurekaInstanceConfigFactory;

/**
 * How to use:
 *  - install this module to access all eureka client functionality.
 *
 * Custom config namespace may be registered as follows:
 * 
 * InjectorBuilder.fromModules(new EurekaClientModule() {
 *      protected void configureEureka() {
 *          bindEurekaInstanceConfigNamespace().toInstance("namespaceForMyInstanceConfig");
 *          bindEurekaClientConfigNamespace().toInstance("namespaceForMyClientAndTransportConfig");
 *      }
 * }).createInjector()
 * 
 *
 * This module support the binding of a custom {@link EurekaInstanceConfigFactory} to supply your own
 * way of providing a config for the creation of an {@link com.netflix.appinfo.InstanceInfo} used for
 * eureka registration.
 *
 * Custom {@link EurekaInstanceConfigFactory} may be registered as follows:
 * 
 * InjectorBuilder.fromModules(new EurekaClientModule() {
 *      protected void configureEureka() {
 *          bindEurekaInstanceConfigFactory().to(MyEurekaInstanceConfigFactory.class);
 *      }
 * }).createInjector()
 * 
 *
 * Note that this module is NOT compatible with the archaius1 based {@link com.netflix.discovery.guice.EurekaModule}
 *
 * @author David Liu
 */
public class EurekaClientModule extends AbstractModule {

    protected LinkedBindingBuilder bindEurekaInstanceConfigNamespace() {
        return bind(String.class).annotatedWith(Names.named(InternalEurekaClientModule.INSTANCE_CONFIG_NAMESPACE_KEY));
    }

    protected LinkedBindingBuilder bindEurekaClientConfigNamespace() {
        return bind(String.class).annotatedWith(Names.named(InternalEurekaClientModule.CLIENT_CONFIG_NAMESPACE_KEY));
    }

    protected LinkedBindingBuilder bindEurekaInstanceConfigFactory() {
        return bind(EurekaInstanceConfigFactory.class);
    }

    @Override
    protected void configure() {
        install(new InternalEurekaClientModule());
        configureEureka();
    }

    protected void configureEureka() {

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy