本文整理汇总了Java中com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList类的典型用法代码示例。如果您正苦于以下问题:Java DiscoveryEnabledNIWSServerList类的具体用法?Java DiscoveryEnabledNIWSServerList怎么用?Java DiscoveryEnabledNIWSServerList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiscoveryEnabledNIWSServerList类属于com.netflix.niws.loadbalancer包,在下文中一共展示了DiscoveryEnabledNIWSServerList类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getClient
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; //导入依赖的package包/类
private LoadBalancingHttpClient<ByteBuf, ByteBuf> getClient(String vip) {
LoadBalancingHttpClient<ByteBuf, ByteBuf> client = httpClients.get(vip);
if (client == null) {
IClientConfig config = IClientConfig.Builder.newBuilder("prana_backend").
withDefaultValues().
withDeploymentContextBasedVipAddresses(vip).
build().
set(IClientConfigKey.Keys.MaxTotalConnections, 2000).
set(IClientConfigKey.Keys.MaxConnectionsPerHost, 2000).
set(IClientConfigKey.Keys.OkToRetryOnAllOperations, false).
set(IClientConfigKey.Keys.NIWSServerListClassName, DiscoveryEnabledNIWSServerList.class.getName());
client = RibbonTransport.newHttpClient(new HttpClientPipelineConfigurator<ByteBuf, ByteBuf>(), config);
httpClients.putIfAbsent(vip, client);
}
return client;
}
开发者ID:Netflix,项目名称:Prana,代码行数:19,代码来源:ProxyHandler.java
示例2: testDynamicServers
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; //导入依赖的package包/类
@Test
public void testDynamicServers() {
ConfigurationManager.getConfigInstance().setProperty("MyService.ribbon." + Keys.DeploymentContextBasedVipAddresses, getVipAddress());
ConfigurationManager.getConfigInstance().setProperty("MyService.ribbon." + Keys.NIWSServerListClassName, DiscoveryEnabledNIWSServerList.class.getName());
HttpResourceGroup group = Ribbon.createHttpResourceGroupBuilder("MyService")
.withClientOptions(ClientOptions.create()
.withMaxAutoRetriesNextServer(3)
.withReadTimeout(300000)).build();
HttpRequestTemplate<ByteBuf> template = group.newTemplateBuilder("test", ByteBuf.class)
.withUriTemplate("/")
.withMethod("GET").build();
RibbonRequest<ByteBuf> request = template
.requestBuilder().build();
String result = request.execute().toString(Charset.defaultCharset());
assertEquals("Hello world", result);
}
开发者ID:Netflix,项目名称:ribbon,代码行数:17,代码来源:DiscoveryEnabledServerListTest.java
示例3: EurekaLoadBalancer
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; //导入依赖的package包/类
/**
* @param config contains vipAddress
*/
@Inject
public EurekaLoadBalancer(ClientConfig config) {
String[] vipAddress_port = config.getLoadBalancerServer().split(":");
if (vipAddress_port.length != 2) {
throw new IllegalArgumentException(String.format(
"EurekaLoadBalancer server should be formatted vipAddress:port ('%s')",
config.getLoadBalancerServer()));
}
this.port = Integer.parseInt(vipAddress_port[1]);
IClientConfig loadBalancerConfig = new DefaultClientConfigImpl();
loadBalancerConfig.loadProperties("suroClient");
loadBalancerConfig.setProperty(CommonClientConfigKey.DeploymentContextBasedVipAddresses, vipAddress_port[0]);
loadBalancerConfig.setProperty(CommonClientConfigKey.NIWSServerListClassName, DiscoveryEnabledNIWSServerList.class.getName());
super.initWithNiwsConfig(loadBalancerConfig);
}
开发者ID:Netflix,项目名称:suro,代码行数:20,代码来源:EurekaLoadBalancer.java
示例4: run
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; //导入依赖的package包/类
@Override
protected String run() throws Exception {
IRule rule = new AvailabilityFilteringRule();
ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList(logWriterApplicationName);
ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<DiscoveryEnabledServer>();
ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder()
.withDynamicServerList(list)
.withRule(rule)
.withServerListFilter(filter)
.buildDynamicServerListLoadBalancer();
Server server = lb.chooseServer();
String url = "http://" + server.getHostPort() + "/log/latest";
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 "ceceived list of size: " + output;
}
开发者ID:guggens,项目名称:log-dropwizard-eureka-mongo-sample,代码行数:30,代码来源:LogReadCommand.java
示例5: run
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; //导入依赖的package包/类
@Override
protected String run() throws Exception {
IRule rule = new AvailabilityFilteringRule();
ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList(logWriterApplicationName);
ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<DiscoveryEnabledServer>();
ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder()
.withDynamicServerList(list)
.withRule(rule)
.withServerListFilter(filter)
.buildDynamicServerListLoadBalancer();
Server server = lb.chooseServer();
int number = new Random().nextInt();
String url = "http://" + server.getHostPort() + "/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,代码行数:31,代码来源:LogWriteCommand.java
示例6: ribbonServerList
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public ServerList<?> ribbonServerList(IClientConfig config, Provider<EurekaClient> eurekaClientProvider) {
if (this.propertiesFactory.isSet(ServerList.class, serviceId)) {
return this.propertiesFactory.get(ServerList.class, config, serviceId);
}
DiscoveryEnabledNIWSServerList discoveryServerList = new DiscoveryEnabledNIWSServerList(
config, eurekaClientProvider);
DomainExtractingServerList serverList = new DomainExtractingServerList(
discoveryServerList, config, this.approximateZoneFromHostname);
return serverList;
}
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:13,代码来源:EurekaRibbonClientConfiguration.java
示例7: testLoadBalancerHappyCase
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; //导入依赖的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);
}
}
}
开发者ID:Netflix,项目名称:ribbon,代码行数:41,代码来源:EurekaDynamicServerListLoadBalancerTest.java
示例8: testLoadBalancer
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; //导入依赖的package包/类
@Test
public void testLoadBalancer() {
IClientConfig config = IClientConfig.Builder.newBuilder().withDefaultValues()
.withDeploymentContextBasedVipAddresses(getVipAddress()).build()
.set(IClientConfigKey.Keys.NIWSServerListClassName, DiscoveryEnabledNIWSServerList.class.getName());
LoadBalancingHttpClient<ByteBuf, ByteBuf> client = RibbonTransport.newHttpClient(config);
LoadBalancerContext lbContext = client.getLoadBalancerContext();
List<Server> serverList = lbContext.getLoadBalancer().getAllServers();
assertEquals(getMockServerList(), serverList);
}
开发者ID:Netflix,项目名称:ribbon,代码行数:11,代码来源:DiscoveryLoadBalancerTest.java
示例9: testShutdownMultiple
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; //导入依赖的package包/类
@Test
public void testShutdownMultiple() {
try {
eurekaClientMock.registerEventListener(EasyMock.anyObject(EurekaEventListener.class));
EasyMock.expectLastCall().anyTimes();
PowerMock.replay(DiscoveryClient.class);
PowerMock.replay(eurekaClientMock);
DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb1 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(
config,
new AvailabilityFilteringRule(),
new DummyPing(),
new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider),
new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(),
new EurekaNotificationServerListUpdater(eurekaClientProvider)
);
DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb2 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(
config,
new AvailabilityFilteringRule(),
new DummyPing(),
new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider),
new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(),
new EurekaNotificationServerListUpdater(eurekaClientProvider)
);
DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb3 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(
config,
new AvailabilityFilteringRule(),
new DummyPing(),
new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider),
new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(),
new EurekaNotificationServerListUpdater(eurekaClientProvider)
);
lb3.shutdown();
lb1.shutdown();
lb2.shutdown();
} finally {
PowerMock.verify(eurekaClientMock);
PowerMock.verify(DiscoveryClient.class);
}
}
开发者ID:Netflix,项目名称:ribbon,代码行数:45,代码来源:EurekaDynamicServerListLoadBalancerTest.java
注:本文中的com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论