本文整理汇总了Java中com.netflix.discovery.DiscoveryClient类的典型用法代码示例。如果您正苦于以下问题:Java DiscoveryClient类的具体用法?Java DiscoveryClient怎么用?Java DiscoveryClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DiscoveryClient类属于com.netflix.discovery包,在下文中一共展示了DiscoveryClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EurekaOneDiscoveryStrategy
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
private EurekaOneDiscoveryStrategy(final EurekaOneDiscoveryStrategyBuilder builder) {
super(builder.logger, builder.properties);
this.namespace = getOrDefault(EUREKA_ONE_SYSTEM_PREFIX, NAMESPACE, "hazelcast");
boolean selfRegistration = getOrDefault(EUREKA_ONE_SYSTEM_PREFIX, SELF_REGISTRATION, true);
// override registration if requested
if (!selfRegistration) {
statusChangeStrategy = new NoopUpdater();
} else {
this.statusChangeStrategy = builder.changeStrategy;
}
if (builder.applicationInfoManager == null) {
this.applicationInfoManager = initializeApplicationInfoManager(builder.discoveryNode);
} else {
this.applicationInfoManager = builder.applicationInfoManager;
}
if (builder.eurekaClient == null) {
this.eurekaClient = new DiscoveryClient(applicationInfoManager, new EurekaOneAwareConfig(this.namespace));
} else {
this.eurekaClient = builder.eurekaClient;
}
}
示例2: testServiceRegistration
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@Test
public void testServiceRegistration() throws InterruptedException {
// Registers "chasis-default-name" with a Eurkea server running on local host.
// http://localhost:8184/v2/apps/chassis-default-name
// tell eureka the service is up which causes a registration
ApplicationInfoManager.getInstance().setInstanceStatus(InstanceInfo.InstanceStatus.UP);
// get application registration from Eureka
DiscoveryClient client = DiscoveryManager.getInstance().getDiscoveryClient();
InstanceInfo instanceInfo = null;
for (int i = 0; (instanceInfo == null) && (i < 50); i++) {
Thread.sleep(5000);
try {
instanceInfo = client.getNextServerFromEureka("default-service", false);
} catch (RuntimeException e) {
// eat not found runtime exception
}
}
Assert.assertNotNull(instanceInfo);
Assert.assertEquals(InstanceStatus.UP, instanceInfo.getStatus());
System.out.println("done");
}
示例3: setupMock
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@Before
public void setupMock(){
List<InstanceInfo> servers = DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.getDummyInstanceInfo("dummy", HOST1, IP1, 8080);
List<InstanceInfo> servers2 = DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.getDummyInstanceInfo("dummy", HOST2, IP2, 8080);
servers.addAll(servers2);
PowerMock.mockStatic(DiscoveryManager.class);
PowerMock.mockStatic(DiscoveryClient.class);
DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class);
DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class);
expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes();
expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes();
expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes();
expect(mockedDiscoveryClient.getInstancesByVipAddress("dummy", false, "region")).andReturn(servers).anyTimes();
replay(DiscoveryManager.class);
replay(DiscoveryClient.class);
replay(mockedDiscoveryManager);
replay(mockedDiscoveryClient);
}
示例4: setupMock
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@Before
public void setupMock(){
List<InstanceInfo> instances = getDummyInstanceInfo("dummy", expected.getHost(), expected.getPort());
PowerMock.mockStatic(DiscoveryManager.class);
PowerMock.mockStatic(DiscoveryClient.class);
DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class);
DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class);
expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes();
expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes();
expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes();
expect(mockedDiscoveryClient.getInstancesByVipAddress("dummy:7001", false, null)).andReturn(instances).anyTimes();
replay(DiscoveryManager.class);
replay(DiscoveryClient.class);
replay(mockedDiscoveryManager);
replay(mockedDiscoveryClient);
}
示例5: setUp
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@Before
public void setUp() {
PowerMock.mockStatic(DiscoveryClient.class);
EasyMock
.expect(DiscoveryClient.getZone(EasyMock.isA(InstanceInfo.class)))
.andReturn("zone")
.anyTimes();
eurekaClientMock = setUpEurekaClientMock(servers);
eurekaClientProvider = new Provider<EurekaClient>() {
@Override
public EurekaClient get() {
return eurekaClientMock;
}
};
config = DefaultClientConfigImpl.getClientConfigWithDefaultValues();
config.setProperty(CommonClientConfigKey.DeploymentContextBasedVipAddresses, vipAddress);
config.setProperty(CommonClientConfigKey.ServerListUpdaterClassName, EurekaNotificationServerListUpdater.class.getName());
}
示例6: setupMock
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@Before
public void setupMock(){
List<InstanceInfo> instances = getDummyInstanceInfo("dummy", getMockServerList());
PowerMock.mockStatic(DiscoveryManager.class);
PowerMock.mockStatic(DiscoveryClient.class);
DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class);
DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class);
expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes();
expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes();
expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes();
expect(mockedDiscoveryClient.getInstancesByVipAddress(getVipAddress(), false, null)).andReturn(instances).anyTimes();
replay(DiscoveryManager.class);
replay(DiscoveryClient.class);
replay(mockedDiscoveryManager);
replay(mockedDiscoveryClient);
}
示例7: getEurekaDetails
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@GET
public Response getEurekaDetails() {
List<EurekaInstanceInfo> instanceInfoList = new ArrayList<EurekaInstanceInfo>();
DiscoveryClient discoveryClient = DiscoveryManager.getInstance().getDiscoveryClient();
if (null != discoveryClient) {
Applications apps = discoveryClient.getApplications();
for (Application app : apps.getRegisteredApplications()) {
for (InstanceInfo inst : app.getInstances()) {
instanceInfoList.add(new EurekaInstanceInfo(inst.getAppName(), inst.getId(), inst.getStatus().name(), inst.getIPAddr(), inst.getHostName()));
}
}
}
GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls();
Gson gson = gsonBuilder.create();
String response = gson.toJson(new KaryonAdminResponse(instanceInfoList));
return Response.ok(response).build();
}
示例8: DynoProxy
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@Inject
public DynoProxy(DiscoveryClient dc, Configuration config) throws DynoException, InterruptedException, ExecutionException {
this.dc = dc;
String cluster = config.getProperty("workflow.dynomite.cluster", null);
String applicationName = config.getAppId();
this.dynoClient = new DynoJedisClient.Builder().withApplicationName(applicationName).withDynomiteClusterName(cluster).withDiscoveryClient(dc)
.build();
}
示例9: DynoQueueDAO
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@Inject
public DynoQueueDAO(DiscoveryClient dc, Configuration config) {
logger.info("DynoQueueDAO::INIT");
this.config = config;
this.domain = config.getProperty("workflow.dyno.keyspace.domain", null);
String cluster = config.getProperty("workflow.dynomite.cluster", null);
final int readConnPort = config.getIntProperty("queues.dynomite.nonQuorum.port", 22122);
EurekaHostsSupplier hostSupplier = new EurekaHostsSupplier(cluster, dc) {
@Override
public List<Host> getHosts() {
List<Host> hosts = super.getHosts();
List<Host> updatedHosts = new ArrayList<>(hosts.size());
hosts.forEach(host -> {
updatedHosts.add(new Host(host.getHostName(), host.getIpAddress(), readConnPort, host.getRack(), host.getDatacenter(), host.isUp() ? Status.Up : Status.Down));
});
return updatedHosts;
}
};
this.dynoClientRead = new DynoJedisClient.Builder().withApplicationName(config.getAppId()).withDynomiteClusterName(cluster).withHostSupplier(hostSupplier).build();
DynoJedisClient dyno = new DynoJedisClient.Builder().withApplicationName(config.getAppId()).withDynomiteClusterName(cluster).withDiscoveryClient(dc).build();
this.dynoClient = dyno;
String region = config.getRegion();
String localDC = config.getAvailabilityZone();
if(localDC == null) {
throw new Error("Availability zone is not defined. Ensure Configuration.getAvailabilityZone() returns a non-null and non-empty value.");
}
localDC = localDC.replaceAll(region, "");
this.ss = new DynoShardSupplier(dyno.getConnPool().getConfiguration().getHostSupplier(), region, localDC);
init();
}
示例10: EurekaVipAddressRoundRobinWithAzAffinityService
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@Inject
public EurekaVipAddressRoundRobinWithAzAffinityService(
@Named("eurekaRoundRobinDiscoveryClientSupplier") Supplier<DiscoveryClient> discoveryClientSupplier,
@Named("currentAvailabilityZone") String currentAvailabilityZone
) {
super(discoveryClientSupplier);
this.currentAvailabilityZone = currentAvailabilityZone;
}
示例11: optionalArgs
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@Bean
DiscoveryClient.DiscoveryClientOptionalArgs optionalArgs(EventBus eventBus, HealthCheckHandler healthCheckHandler) {
DiscoveryClient.DiscoveryClientOptionalArgs args = new DiscoveryClient.DiscoveryClientOptionalArgs();
args.setEventBus(eventBus);
args.setHealthCheckHandlerProvider(new StaticProvider<>(healthCheckHandler));
return args;
}
示例12: EurekaStatusSubscriber
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
public EurekaStatusSubscriber(ApplicationEventPublisher publisher, EventBus eventBus, DiscoveryClient discoveryClient) {
this.publisher = Objects.requireNonNull(publisher, "publisher");
this.eventBus = Objects.requireNonNull(eventBus, "eventBus");
publish(new StatusChangeEvent(
InstanceInfo.InstanceStatus.UNKNOWN,
discoveryClient.getInstanceRemoteStatus()));
try {
eventBus.registerSubscriber(this);
} catch (InvalidSubscriberException ise) {
throw new RuntimeException(ise);
}
}
示例13: CloudEurekaClient
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
public CloudEurekaClient(ApplicationInfoManager applicationInfoManager,
EurekaClientConfig config,
AbstractDiscoveryClientOptionalArgs<?> args,
ApplicationEventPublisher publisher) {
super(applicationInfoManager, config, args);
this.applicationInfoManager = applicationInfoManager;
this.publisher = publisher;
this.eurekaTransportField = ReflectionUtils.findField(DiscoveryClient.class, "eurekaTransport");
ReflectionUtils.makeAccessible(this.eurekaTransportField);
}
示例14: testLoadBalancerHappyCase
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@Test
public void testLoadBalancerHappyCase() throws Exception {
Assert.assertNotEquals("the two test server list counts should be different",
secondServerListSize, initialServerListSize);
DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb = null;
try {
Capture<EurekaEventListener> eventListenerCapture = new Capture<EurekaEventListener>();
eurekaClientMock.registerEventListener(EasyMock.capture(eventListenerCapture));
PowerMock.replay(DiscoveryClient.class);
PowerMock.replay(eurekaClientMock);
// actual testing
// initial creation and loading of the first serverlist
lb = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(
config,
new AvailabilityFilteringRule(),
new DummyPing(),
new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider),
new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(),
new EurekaNotificationServerListUpdater(eurekaClientProvider)
);
Assert.assertEquals(initialServerListSize, lb.getServerCount(false));
// trigger an eureka CacheRefreshEvent
eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
Assert.assertTrue(verifyFinalServerListCount(secondServerListSize, lb));
} finally {
if (lb != null) {
lb.shutdown();
PowerMock.verify(eurekaClientMock);
PowerMock.verify(DiscoveryClient.class);
}
}
}
示例15: EVCacheClientPoolManager
import com.netflix.discovery.DiscoveryClient; //导入依赖的package包/类
@Inject
public EVCacheClientPoolManager(ApplicationInfoManager applicationInfoManager, DiscoveryClient discoveryClient, Provider<IConnectionFactoryProvider> connectionFactoryprovider) {
instance = this;
this.applicationInfoManager = applicationInfoManager;
this.discoveryClient = discoveryClient;
this.connectionFactoryprovider = connectionFactoryprovider;
this.evcacheEventListenerList = new ArrayList<EVCacheEventListener>();
this.asyncExecutor = new EVCacheScheduledExecutor(Runtime.getRuntime().availableProcessors(),Runtime.getRuntime().availableProcessors(), 30, TimeUnit.SECONDS, new ThreadPoolExecutor.CallerRunsPolicy(), "scheduled");
asyncExecutor.prestartAllCoreThreads();
this.syncExecutor = new EVCacheExecutor(Runtime.getRuntime().availableProcessors(),Runtime.getRuntime().availableProcessors(), 30, TimeUnit.SECONDS, new ThreadPoolExecutor.CallerRunsPolicy(), "pool");
syncExecutor.prestartAllCoreThreads();
initAtStartup();
}