Search in sources :

Example 11 with EurekaClient

use of com.netflix.discovery.EurekaClient in project eureka by Netflix.

the class ExampleEurekaService method main.

public static void main(String[] args) {
    DynamicPropertyFactory configInstance = com.netflix.config.DynamicPropertyFactory.getInstance();
    ApplicationInfoManager applicationInfoManager = initializeApplicationInfoManager(new MyDataCenterInstanceConfig());
    EurekaClient eurekaClient = initializeEurekaClient(applicationInfoManager, new DefaultEurekaClientConfig());
    ExampleServiceBase exampleServiceBase = new ExampleServiceBase(applicationInfoManager, eurekaClient, configInstance);
    try {
        exampleServiceBase.start();
    } finally {
        // the stop calls shutdown on eurekaClient
        exampleServiceBase.stop();
    }
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DynamicPropertyFactory(com.netflix.config.DynamicPropertyFactory) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Example 12 with EurekaClient

use of com.netflix.discovery.EurekaClient in project eureka by Netflix.

the class DiscoveryClientResource method setupInjector.

public static EurekaClient setupInjector(InstanceInfo clientInstanceInfo) {
    DefaultEurekaClientConfig config = new DefaultEurekaClientConfig();
    // setup config in advance, used in initialize converter
    DiscoveryManager.getInstance().setEurekaClientConfig(config);
    EurekaClient client = new DiscoveryClient(clientInstanceInfo, config);
    ApplicationInfoManager.getInstance().initComponent(new MyDataCenterInstanceConfig());
    return client;
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient)

Example 13 with EurekaClient

use of com.netflix.discovery.EurekaClient in project eureka by Netflix.

the class DiscoveryClientResource method setupDiscoveryClient.

public static EurekaClient setupDiscoveryClient(InstanceInfo clientInstanceInfo) {
    DefaultEurekaClientConfig config = new DefaultEurekaClientConfig();
    // setup config in advance, used in initialize converter
    ApplicationInfoManager applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), clientInstanceInfo);
    DiscoveryManager.getInstance().setEurekaClientConfig(config);
    EurekaClient client = new DiscoveryClient(applicationInfoManager, config);
    return client;
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Example 14 with EurekaClient

use of com.netflix.discovery.EurekaClient in project eureka by Netflix.

the class EurekaModuleTest method testDI.

@SuppressWarnings("deprecation")
@Test
public void testDI() {
    InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
    Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
    EurekaClient eurekaClient = injector.getInstance(EurekaClient.class);
    DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClient(), eurekaClient);
    Assert.assertEquals(DiscoveryManager.getInstance().getDiscoveryClient(), discoveryClient);
    Assert.assertEquals(eurekaClient, discoveryClient);
    EurekaClientConfig eurekaClientConfig = injector.getInstance(EurekaClientConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClientConfig(), eurekaClientConfig);
    EurekaInstanceConfig eurekaInstanceConfig = injector.getInstance(EurekaInstanceConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaInstanceConfig(), eurekaInstanceConfig);
    Binding<TransportClientFactories> binding = injector.getExistingBinding(Key.get(TransportClientFactories.class));
    // no bindings so defaulting to default of jersey1
    Assert.assertNull(binding);
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) TransportClientFactories(com.netflix.discovery.shared.transport.jersey.TransportClientFactories) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 15 with EurekaClient

use of com.netflix.discovery.EurekaClient in project ribbon by Netflix.

the class DiscoveryEnabledNIWSServerList method obtainServersViaDiscovery.

private List<DiscoveryEnabledServer> obtainServersViaDiscovery() {
    List<DiscoveryEnabledServer> serverList = new ArrayList<DiscoveryEnabledServer>();
    if (eurekaClientProvider == null || eurekaClientProvider.get() == null) {
        logger.warn("EurekaClient has not been initialized yet, returning an empty list");
        return new ArrayList<DiscoveryEnabledServer>();
    }
    EurekaClient eurekaClient = eurekaClientProvider.get();
    if (vipAddresses != null) {
        for (String vipAddress : vipAddresses.split(",")) {
            // if targetRegion is null, it will be interpreted as the same region of client
            List<InstanceInfo> listOfInstanceInfo = eurekaClient.getInstancesByVipAddress(vipAddress, isSecure, targetRegion);
            for (InstanceInfo ii : listOfInstanceInfo) {
                if (ii.getStatus().equals(InstanceStatus.UP)) {
                    if (shouldUseOverridePort) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Overriding port on client name: " + clientName + " to " + overridePort);
                        }
                        // copy is necessary since the InstanceInfo builder just uses the original reference,
                        // and we don't want to corrupt the global eureka copy of the object which may be
                        // used by other clients in our system
                        InstanceInfo copy = new InstanceInfo(ii);
                        if (isSecure) {
                            ii = new InstanceInfo.Builder(copy).setSecurePort(overridePort).build();
                        } else {
                            ii = new InstanceInfo.Builder(copy).setPort(overridePort).build();
                        }
                    }
                    DiscoveryEnabledServer des = new DiscoveryEnabledServer(ii, isSecure, shouldUseIpAddr);
                    des.setZone(DiscoveryClient.getZone(ii));
                    serverList.add(des);
                }
            }
            if (serverList.size() > 0 && prioritizeVipAddressBasedServers) {
                // if the current vipAddress has servers, we dont use subsequent vipAddress based servers
                break;
            }
        }
    }
    return serverList;
}
Also used : ArrayList(java.util.ArrayList) EurekaClient(com.netflix.discovery.EurekaClient) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Aggregations

EurekaClient (com.netflix.discovery.EurekaClient)21 Test (org.junit.Test)13 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)7 DiscoveryClient (com.netflix.discovery.DiscoveryClient)6 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)6 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)5 InstanceInfo (com.netflix.appinfo.InstanceInfo)5 CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)5 EurekaEventListener (com.netflix.discovery.EurekaEventListener)5 Capture (org.easymock.Capture)5 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)4 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)4 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 Archaius2VipAddressResolver (com.netflix.appinfo.providers.Archaius2VipAddressResolver)2 VipAddressResolver (com.netflix.appinfo.providers.VipAddressResolver)2 TransportClientFactories (com.netflix.discovery.shared.transport.jersey.TransportClientFactories)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 Injector (com.google.inject.Injector)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1