本文整理汇总了Java中com.netflix.discovery.DiscoveryManager类的典型用法代码示例。如果您正苦于以下问题:Java DiscoveryManager类的具体用法?Java DiscoveryManager怎么用?Java DiscoveryManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiscoveryManager类属于com.netflix.discovery包,在下文中一共展示了DiscoveryManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testServiceRegistration
import com.netflix.discovery.DiscoveryManager; //导入依赖的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");
}
开发者ID:Kixeye,项目名称:chassis,代码行数:24,代码来源:ChassisEurekaRegistrationTest.java
示例2: setupMock
import com.netflix.discovery.DiscoveryManager; //导入依赖的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);
}
开发者ID:Netflix,项目名称:ribbon,代码行数:27,代码来源:DiscoveryEnabledLoadBalancerSupportsUseIpAddrTest.java
示例3: setupMock
import com.netflix.discovery.DiscoveryManager; //导入依赖的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);
}
开发者ID:Netflix,项目名称:ribbon,代码行数:22,代码来源:LBBuilderTest.java
示例4: setupMock
import com.netflix.discovery.DiscoveryManager; //导入依赖的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);
}
开发者ID:Netflix,项目名称:ribbon,代码行数:21,代码来源:MockedDiscoveryServerListTest.java
示例5: configure
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
@Override
protected void configure() {
LOG.info("Configuring EurekaModule");
// Initialize eureka
// TODO: Move this to a bootstrap thingy
DiscoveryManager.getInstance().initComponent(
new CloudInstanceConfig(),
new DefaultEurekaClientConfig());
// Eureka - Astyanax integration
MapBinder<String, HostSupplierProvider> hostSuppliers = MapBinder.newMapBinder(binder(), String.class, HostSupplierProvider.class);
hostSuppliers.addBinding("eureka").to(EurekaAstyanaxHostSupplier.class);
//bind(ClusterDiscoveryService.class).to(EurekaClusterDiscoveryService.class).asEagerSingleton();
}
开发者ID:Netflix,项目名称:staash,代码行数:18,代码来源:EurekaModule.java
示例6: getEurekaDetails
import com.netflix.discovery.DiscoveryManager; //导入依赖的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();
}
开发者ID:Netflix,项目名称:karyon,代码行数:20,代码来源:EurekaResource.java
示例7: getConfigUrl
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
private String getConfigUrl() throws Exception {
List<InstanceInfo> instances = DiscoveryManager.getInstance().getLookupService().getApplications().getRegisteredApplications("micro-service-netflix-config-server").getInstances();
for(InstanceInfo instanceInfo : instances) {
try {
return instanceInfo.getHomePageUrl();
} catch (Exception e) {
// do nothing
}
}
throw new Exception("config url is null");
}
开发者ID:colddew,项目名称:micro-service-netflix,代码行数:14,代码来源:NetflixEurekaPolledConfigurationSource.java
示例8: start
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
@Override
public void start() throws Exception {
EurekaClientConfiguration eurekaClientConfiguration = configuration.getEureka();
ServerFactory serverFactory = configuration.getServerFactory();
BaseConfiguration baseConfiguration = new BaseConfiguration();
baseConfiguration.setProperty(eurekaNamespace + "name", eurekaClientConfiguration.getName());
baseConfiguration.setProperty(eurekaNamespace + "vipAddress", eurekaClientConfiguration.getVipAddress());
baseConfiguration.setProperty(eurekaNamespace + "serviceUrl.default", eurekaClientConfiguration.getDefaultServiceUrl());
baseConfiguration.setProperty(eurekaNamespace + "port", eurekaClientConfiguration.getPort());
Integer port = DropwizardServerHelpers.getPort(serverFactory);
Integer adminPort = DropwizardServerHelpers.getAdminPort(serverFactory);
baseConfiguration.setProperty(eurekaNamespace + "healthCheckUrl", String.format("http://${eureka.hostname}:%d/healthcheck", adminPort));
baseConfiguration.setProperty(eurekaNamespace + "secureHealthCheckUrl", String.format("http://${eureka.hostname}:%d/healthcheck", adminPort));
baseConfiguration.setProperty(eurekaNamespace + "statusPageUrl", String.format("http://${eureka.hostname}:%d/healthcheck", adminPort));
ConfigurationManager.loadPropertiesFromConfiguration(baseConfiguration);
EurekaInstanceConfig eurekaInstanceConfig = createEurekaInstanceConfig(discoveryMetadataProviders);
DiscoveryManager.getInstance().initComponent(eurekaInstanceConfig, new DefaultEurekaClientConfig(eurekaNamespace));
DiscoveryManager.getInstance().getDiscoveryClient().registerHealthCheckCallback(healthCheck);
markAsUp();
}
开发者ID:guggens,项目名称:log-dropwizard-eureka-mongo-sample,代码行数:28,代码来源:EurekaInstance.java
示例9: produce
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
@GET
@Timed
public String produce() {
Application telematicLogWriter = DiscoveryManager.getInstance().getDiscoveryClient().getApplication(logWriterApplicationName);
if (telematicLogWriter == null || telematicLogWriter.getInstances().isEmpty()) {
return "broken";
}
InstanceInfo instanceInfo = telematicLogWriter.getInstances().iterator().next();
int number = new Random().nextInt();
String url = "http://" + instanceInfo.getIPAddr() + ":" + instanceInfo.getPort() + "/log?name=ProducedLog" + number;
WebResource webResource = client
.resource(url);
ClientResponse response = webResource.accept("application/json")
.get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus() + " url " + url);
}
String output = response.getEntity(String.class);
return "fired " + number + " to url:" + url + " with result " + output;
}
开发者ID:guggens,项目名称:log-dropwizard-eureka-mongo-sample,代码行数:30,代码来源:LogProducerResource.java
示例10: HealthMonitor
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
@Inject
public HealthMonitor(IConfiguration config, InstanceManager instanceManager, HttpModule httpModule) {
super(config);
this.instanceManager = instanceManager;
this.httpModule = httpModule;
healthReporter = new Elasticsearch_HealthReporter();
discoveryClient = DiscoveryManager.getInstance().getDiscoveryClient();
Monitors.registerObject(healthReporter);
}
开发者ID:Netflix,项目名称:Raigad,代码行数:10,代码来源:HealthMonitor.java
示例11: healthCheckRegistry
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
/**
* Initializes the health check registry
*
* @return health check registry bean
*/
@Bean
public HealthCheckRegistry healthCheckRegistry(ApplicationContext context, DiscoveryManager eureka) {
final HealthCheckRegistry bean = new HealthCheckRegistry();
// auto-register beans implementing health checks
Map<String, HealthCheck> healthChecks = context.getBeansOfType(HealthCheck.class);
for (HealthCheck check : healthChecks.values()) {
bean.register(check.getClass().getName(), check);
}
// connect health checks into Eureka
if (!disableEureka) {
eureka.getDiscoveryClient().registerHealthCheckCallback(
new HealthCheckCallback() {
@Override
public boolean isHealthy() {
for (Entry<String, HealthCheck.Result> entry : bean.runHealthChecks().entrySet()) {
if (!entry.getValue().isHealthy()) {
return false;
}
}
return true;
}
});
}
return bean;
}
开发者ID:Kixeye,项目名称:chassis,代码行数:34,代码来源:ChassisConfiguration.java
示例12: get
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
@Override
public synchronized EurekaClient get() {
if (eurekaClient == null) {
eurekaClient = DiscoveryManager.getInstance().getDiscoveryClient();
}
return eurekaClient;
}
开发者ID:Netflix,项目名称:ribbon,代码行数:9,代码来源:LegacyEurekaClientProvider.java
示例13: configure
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
@Override
protected void configure() {
LOG.info("Configuring EurekaModule");
DiscoveryManager.getInstance().initComponent(
new CloudInstanceConfig(),
new DefaultEurekaClientConfig());
// Eureka - Astyanax integration
MapBinder<String, HostSupplierProvider> hostSuppliers = MapBinder.newMapBinder(binder(), String.class, HostSupplierProvider.class);
hostSuppliers.addBinding("eureka").to(EurekaAstyanaxHostSupplier.class).asEagerSingleton();
//bind(ClusterDiscoveryService.class).to(EurekaClusterDiscoveryService.class).asEagerSingleton();
}
开发者ID:Netflix,项目名称:staash,代码行数:16,代码来源:EurekaModule.java
示例14: shutdown
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
@PreDestroy
public void shutdown() {
// TODO: Move this somewhere else
LOG.info("Shutting down Eureka client");
DiscoveryManager.getInstance().shutdownComponent();
client = null;
}
开发者ID:Netflix,项目名称:staash,代码行数:8,代码来源:EurekaClusterDiscoveryService.java
示例15: initDiscoveryManager
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
@SuppressWarnings("deprecation")
protected void initDiscoveryManager(EurekaInstanceConfig eurekaInstanceConfig,
EurekaClientConfig eurekaClientConfig) {
DiscoveryManager.getInstance().initComponent(eurekaInstanceConfig, eurekaClientConfig);
}
开发者ID:Nike-Inc,项目名称:riposte,代码行数:6,代码来源:EurekaHandler.java
示例16: shutdownDiscoveryManager
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
@SuppressWarnings("deprecation")
protected void shutdownDiscoveryManager() {
DiscoveryManager.getInstance().shutdownComponent();
}
开发者ID:Nike-Inc,项目名称:riposte,代码行数:5,代码来源:EurekaHandler.java
示例17: eurekaDiscoveryManager
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
/***
* Initializes Eureka Client Library (aka DiscoveryManager)
*
* @return discovery manager bean
*/
@Bean(destroyMethod = "shutdownComponent")
public DiscoveryManager eurekaDiscoveryManager(MetadataCollector metadataCollector) {
final DiscoveryManager bean = DiscoveryManager.getInstance();
if (!disableEureka) {
// set eureka.port via http.port if not already set
int httpPort = ConfigurationManager.getConfigInstance().getInt("http.port",-1);
int httpsPort = ConfigurationManager.getConfigInstance().getInt("https.port",-1);
int eurekaPort = ConfigurationManager.getConfigInstance().getInt("eureka.port",-1);
int eurekaSecurePort = ConfigurationManager.getConfigInstance().getInt("eureka.securePort",-1);
boolean httpPortEnabled = ConfigurationManager.getConfigInstance().getBoolean("http.enabled", false);
boolean httpsPortEnabled = ConfigurationManager.getConfigInstance().getBoolean("https.enabled", false);
if (httpPort != -1 && eurekaPort == -1) {
ConfigurationManager.getConfigInstance().setProperty("eureka.port", httpPort);
ConfigurationManager.getConfigInstance().setProperty("eureka.port.enabled", httpPortEnabled);
}
if(httpsPort != -1 && eurekaSecurePort == -1){
ConfigurationManager.getConfigInstance().setProperty("eureka.securePort", httpsPort);
ConfigurationManager.getConfigInstance().setProperty("eureka.securePort.enabled", httpsPortEnabled);
}
// set eureka.name and eureka.vipAddress with @SpringApp name if not already set
String appName = ConfigurationManager.getConfigInstance().getString("app.name",null);
String eurekaName = ConfigurationManager.getConfigInstance().getString("eureka.name",null);
String eurekaVip = ConfigurationManager.getConfigInstance().getString("eureka.vipAddress",null);
String eurekaSecureVipAddress = ConfigurationManager.getConfigInstance().getString("eureka.secureVipAddress",null);
if (appName != null && eurekaName == null) {
ConfigurationManager.getConfigInstance().setProperty("eureka.name", appName);
}
if (appName != null && eurekaVip == null) {
ConfigurationManager.getConfigInstance().setProperty("eureka.vipAddress", appName);
}
if (appName != null && eurekaSecureVipAddress == null) {
ConfigurationManager.getConfigInstance().setProperty("eureka.secureVipAddress", appName);
}
// initialize DiscoveryManager if it hasn't already been done
if (ApplicationInfoManager.getInstance().getInfo() == null) {
EurekaInstanceConfig config;
switch (datacenter.toLowerCase()) {
case "amazon":
case "cloud":
config = new KixeyeCloudInstanceConfig(metadataCollector);
break;
default:
config = new KixeyeMyDataCenterInstanceConfig(metadataCollector);
break;
}
bean.initComponent(config, new DefaultEurekaClientConfig());
}
}
return bean;
}
开发者ID:Kixeye,项目名称:chassis,代码行数:58,代码来源:EurekaConfiguration.java
示例18: afterMock
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
@After
public void afterMock(){
verify(DiscoveryManager.class);
verify(DiscoveryClient.class);
}
开发者ID:Netflix,项目名称:ribbon,代码行数:6,代码来源:DiscoveryEnabledLoadBalancerSupportsUseIpAddrTest.java
示例19: EurekaAstyanaxHostSupplier
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
public EurekaAstyanaxHostSupplier() {
this.eurekaClient = DiscoveryManager.getInstance().getDiscoveryClient();
Preconditions.checkNotNull(this.eurekaClient);
}
开发者ID:Netflix,项目名称:staash,代码行数:5,代码来源:EurekaAstyanaxHostSupplier.java
示例20: initialize
import com.netflix.discovery.DiscoveryManager; //导入依赖的package包/类
@PostConstruct
public void initialize() {
LOG.info("Initializing Eureka client");
client = DiscoveryManager.getInstance().getDiscoveryClient();
}
开发者ID:Netflix,项目名称:staash,代码行数:6,代码来源:EurekaClusterDiscoveryService.java
注:本文中的com.netflix.discovery.DiscoveryManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论