当前位置: 首页>>代码示例>>Java>>正文


Java ServiceDiscoveryBuilder类代码示例

本文整理汇总了Java中org.apache.curator.x.discovery.ServiceDiscoveryBuilder的典型用法代码示例。如果您正苦于以下问题:Java ServiceDiscoveryBuilder类的具体用法?Java ServiceDiscoveryBuilder怎么用?Java ServiceDiscoveryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServiceDiscoveryBuilder类属于org.apache.curator.x.discovery包,在下文中一共展示了ServiceDiscoveryBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
@Override
public void start() {
    startCuratorClient();

    group = getOrDefault(ZookeeperDiscoveryProperties.GROUP, DEFAULT_GROUP);
    try {
        String path = getOrDefault(ZookeeperDiscoveryProperties.ZOOKEEPER_PATH, DEFAULT_PATH);
        ServiceDiscoveryBuilder<Void> discoveryBuilder = ServiceDiscoveryBuilder.builder(Void.class)
                .basePath(path)
                .client(client);

        if (isMember()) {
            //register members only into zookeeper
            //there no need to register clients
            prepareServiceInstance();
            discoveryBuilder.thisInstance(serviceInstance);
        }
        serviceDiscovery = discoveryBuilder.build();
        serviceDiscovery.start();
    } catch (Exception e) {
        throw new IllegalStateException("Error while talking to ZooKeeper. ", e);
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-zookeeper,代码行数:24,代码来源:ZookeeperDiscoveryStrategy.java

示例2: init

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
private void init() {
    this.zookeeperBasePath = PathHelper.getPathHelper(EntityType.STACK, config.getZooKeeperBasePath()).getPath();
    serviceDiscovery = (ServiceDiscoveryImpl<MetaData>) ServiceDiscoveryBuilder.builder(MetaData.class)
            .client(curatorFramework)
            .basePath(this.zookeeperBasePath)
            .build();
    try {
        serviceDiscovery.start();
    } catch (Exception e) {
        String description = "ZooKeeper connection issue should not cause this exception. Verified on org.apache.curator:curator-x-discovery:2.4.1" +
                " serviceDiscovery.start() is not actually communicating with ZooKeeper unless ServiceDiscoveryBuilder.thisInstance(ServiceInstance) was called." +
                " If exception was thrown our assumption is curator-x-discovery source code was incompatible changed.";

        throw new RuntimeException(description, e);
    }
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:17,代码来源:DiscoveryServiceProviderFactory.java

示例3: getGeolocationServiceProvider

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
private static ServiceProvider<Object> getGeolocationServiceProvider() throws Exception {
	if(geolocationServiceProvider == null) {
		CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient("192.168.99.100:2181", new RetryNTimes(5, 1000));
		curatorFramework.start();

		ServiceDiscovery<Object> serviceDiscovery = ServiceDiscoveryBuilder.builder(Object.class)
				.basePath("com.packt.microservices")
				.client(curatorFramework)
				.build();
		serviceDiscovery.start();

		geolocationServiceProvider = serviceDiscovery.serviceProviderBuilder()
				.serviceName("geolocation")
				.build();
		geolocationServiceProvider.start();
	}
	return geolocationServiceProvider;
}
 
开发者ID:PacktPublishing,项目名称:Microservices-Deployment-Cookbook,代码行数:19,代码来源:ZookeeperServiceDiscovery.java

示例4: startZookeeper

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
@Before
public void startZookeeper() throws Exception {
  zkTestServer = new TestingServer(2181);
  cli = CuratorFrameworkFactory.newClient(zkTestServer.getConnectString(), new RetryOneTime(2000));
  cli.start();

  discovery = ServiceDiscoveryBuilder.builder(String.class)
      .client(cli)
      .basePath("/discovery")
      .watchInstances(true)
      .build();

  discovery.start();
  vertx = Vertx.vertx();
  sd = io.vertx.servicediscovery.ServiceDiscovery.create(vertx);
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:17,代码来源:ZookeeperBridgeTest.java

示例5: buildServiceDiscoveryWith

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
private ServiceDiscovery<ZookeeperInstance> buildServiceDiscoveryWith(ZookeeperConfiguration configuration, CuratorFramework curator,
		InstanceSerializer<ZookeeperInstance> serializer) {

	try {
		if (!CuratorFrameworkState.STARTED.equals(curator.getState())) {
			curator.start();
		}

		ServiceDiscovery<ZookeeperInstance> serviceDiscovery = ServiceDiscoveryBuilder.builder(ZookeeperInstance.class)
				.client(curator)
					.basePath(configuration.root())
					.serializer(serializer)
						.build();

		serviceDiscovery.start();

		return serviceDiscovery;
	} catch (Exception e) {
		throw new ZookeeperServiceDiscoveryException("Error on create Zookeeper ServiceDiscovery", e);
	}
}
 
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:22,代码来源:ZookeeperServiceDiscovery.java

示例6: ExampleServer

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
public ExampleServer(CuratorFramework client, String path, String serviceName, String description) throws Exception
{
    // in a real application, you'd have a convention of some kind for the URI layout
    UriSpec     uriSpec = new UriSpec("{scheme}://foo.com:{port}");

    thisInstance = ServiceInstance.<InstanceDetails>builder()
        .name(serviceName)
        .payload(new InstanceDetails(description))
        .port((int)(65535 * Math.random())) // in a real application, you'd use a common port
        .uriSpec(uriSpec)
        .build();

    // if you mark your payload class with @JsonRootName the provided JsonInstanceSerializer will work
    JsonInstanceSerializer<InstanceDetails> serializer = new JsonInstanceSerializer<InstanceDetails>(InstanceDetails.class);

    serviceDiscovery = ServiceDiscoveryBuilder.builder(InstanceDetails.class)
        .client(client)
        .basePath(path)
        .serializer(serializer)
        .thisInstance(thisInstance)
        .build();
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:23,代码来源:ExampleServer.java

示例7: createServiceProvider

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
synchronized private void createServiceProvider() {
  ServiceDiscovery<Map> serviceDiscovery = ServiceDiscoveryBuilder.builder(Map.class)
    .client(curator)
    .basePath(Constants.SERVICES_PATH)
    .serializer(new ServiceInstanceSerializer<>(Map.class))
    .build();

  serviceProvider = serviceDiscovery.serviceProviderBuilder()
    .serviceName(serviceName)
    .providerStrategy(new RoundRobinStrategy<>())
    // .threadFactory()
    // .additionalFilter()
    // .downInstancePolicy()
    .build();

  try {
    serviceProvider.start();
    log.debug("service provider started working.");
  } catch (Exception ex) {
    throw new ApiCallException("Cannot start service provider working", ex);
  }
}
 
开发者ID:tommyxu,项目名称:curator-service-api-client,代码行数:23,代码来源:CuratorServiceProviderFinder.java

示例8: Server

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
public Server(CuratorFramework client, Instance instance, String basePath) throws Exception
  {
this();
      UriSpec     uriSpec = new UriSpec("{scheme}://"+ instance.getIpAddress() + ":{port}");
      this.basePath = basePath;
      this.thisInstance = ServiceInstance.<Instance>builder()
          .name(instance.getServiceName())
          .payload(instance)
          .port(instance.getPort()) 
          .uriSpec(uriSpec)
          .build();

      JsonInstanceSerializer<Instance> serializer = new JsonInstanceSerializer<Instance>(Instance.class);

      this.serviceDiscovery = ServiceDiscoveryBuilder.builder(Instance.class)
          .client(client)
          .basePath(this.basePath)
          .serializer(serializer)
          .thisInstance(thisInstance)
          .build();
  }
 
开发者ID:cleuton,项目名称:servkeeper,代码行数:22,代码来源:Server.java

示例9: ZookeeperWrapper

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
public ZookeeperWrapper(String zkAddress) throws Exception {
	this.zkAddress = zkAddress;
	this.curatorFramework = 
			CuratorFrameworkFactory.newClient(this.zkAddress, new RetryNTimes(5, 1000));
	curatorFramework.start();

	
       this.serializer = new JsonInstanceSerializer<>(Instance.class);

	this.serviceDiscovery = ServiceDiscoveryBuilder.builder(Instance.class)
			    .basePath(this.BASE_NAME)
			    .serializer(serializer)
			    .client(curatorFramework).build();
	serviceDiscovery.start();
	this.servers = new ArrayList<Server>();
}
 
开发者ID:cleuton,项目名称:servkeeper,代码行数:17,代码来源:ZookeeperWrapper.java

示例10: configure

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
@SuppressWarnings("PMD.AvoidCatchingGenericException")
private void configure() {
    System.setProperty("zookeeper.sasl.client", "false");
    Environment env = beanFactory.getBean(Environment.class);
    String zkHostAddress = env.getProperty(RegistryBeanProviderFactory.SERVICE_DISCOVERY_ZK_HOST);
    this.curatorFramework = CuratorFrameworkFactory.newClient(zkHostAddress, new ExponentialBackoffRetry(1000, 3));

    curatorFramework.start();

    this.serviceDiscovery = ServiceDiscoveryBuilder.builder(Void.class).client(this.curatorFramework)
            .basePath("/services").build();

    try {
        getServiceDiscovery().start();
    } catch (Exception e) {
        throw new IllegalStateException("Service discovery start failed.", e);
    }

    this.zookeeperRegistry = new ZookeeperRegistry(getServiceDiscovery());
    this.zookeeperFetcher = new ZookeeperFetcher(getServiceDiscovery());
    this.zookeeperProxyGenerator = new ZookeeperProxyGenerator(beanFactory);
}
 
开发者ID:PayU-Tech,项目名称:Ratel,代码行数:23,代码来源:ZookeeperRegistryBeanProvider.java

示例11: start

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
@Override
public void start() {
    startCuratorClient();

    Address privateAddress = thisNode.getPrivateAddress();
    group = getOrDefault(ZookeeperDiscoveryProperties.GROUP, DEFAULT_GROUP);
    try {
        serviceInstance = ServiceInstance.<Void>builder()
                .uriSpec(new UriSpec("{scheme}://{address}:{port}"))
                .address(privateAddress.getHost())
                .port(privateAddress.getPort())
                .name(group)
                .build();

        String path = getOrDefault(ZookeeperDiscoveryProperties.ZOOKEEPER_PATH, DEFAULT_PATH);
        serviceDiscovery = ServiceDiscoveryBuilder.builder(Void.class)
                .basePath(path)
                .client(client)
                .thisInstance(serviceInstance)
                .build();

        serviceDiscovery.start();
    } catch (Exception e) {
        throw new IllegalStateException("Error while talking to ZooKeeper. ", e);
    }
}
 
开发者ID:jerrinot,项目名称:hzkeeper,代码行数:27,代码来源:ZookeeperDiscovery.java

示例12: ApplicationServer

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
public ApplicationServer(CuratorFramework client, String host, String contextPath, String basePath, String serviceName) throws Exception
{
    Preconditions.checkState(!Strings.isNullOrEmpty(host));
    UriSpec uriSpec = new UriSpec(String.format("{scheme}://%s:{port}%s", host, this.contextPath = contextPath));
    
    int port = SystemUtils2.getIntegerProperty("org.excalibur.server.port", 8080);
    
    thisInstance = ServiceInstance.<ServiceDetails>builder()
            .name(serviceName)
            .payload(new ServiceDetails())
            .port(port)
            .uriSpec(uriSpec)
            .build();
    
    serviceDiscovery = ServiceDiscoveryBuilder.builder(ServiceDetails.class)
            .client(client)
            .basePath(basePath)
            .thisInstance(thisInstance)
            .build();
    
    server = new Server(port);
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:23,代码来源:ApplicationServer.java

示例13: InstanceServer

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
public InstanceServer(CuratorFramework client, String path, ServiceDetails details) throws Exception
{
    UriSpec uriSpec = new UriSpec("{scheme}://localhost:{port}");

    thisInstance = ServiceInstance.<ServiceDetails> builder()
            .name(details.getName())
            .payload(details)
            .port(details.getPort())
            .uriSpec(uriSpec)
            .build();
    
    this.serviceDiscovery = ServiceDiscoveryBuilder.builder(ServiceDetails.class)
            .client(client)
            .basePath(path)
            .thisInstance(thisInstance)
            .build();
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:18,代码来源:InstanceServer.java

示例14: testSetSerializer

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
@Test
public void testSetSerializer() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    ServiceDiscoveryBuilder<Object> builder = ServiceDiscoveryBuilder.builder(Object.class).client(client);
    builder.serializer(new InstanceSerializer<Object>()
    {
        @Override
        public byte[] serialize(ServiceInstance<Object> instance)
        {
            return null;
        }

        @Override
        public ServiceInstance<Object> deserialize(byte[] bytes)
        {
            return null;
        }
    });

    ServiceDiscoveryImpl<?> discovery = (ServiceDiscoveryImpl<?>) builder.basePath("/path").build();
    Assert.assertNotNull(discovery.getSerializer(), "default serializer not set");
    Assert.assertFalse(discovery.getSerializer() instanceof JsonInstanceSerializer, "set serializer is JSON");
}
 
开发者ID:apache,项目名称:curator,代码行数:25,代码来源:TestServiceDiscoveryBuilder.java

示例15: testBasic

import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入依赖的package包/类
@Test
public void testBasic() throws Exception
{
    CuratorFramework client = null;
    ServiceDiscovery<String> discovery = null;
    try
    {
        client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
        client.start();

        ServiceInstance<String> instance = ServiceInstance.<String>builder().payload("thing").name("test").port(10064).build();
        discovery = ServiceDiscoveryBuilder.builder(String.class).basePath("/test").client(client).thisInstance(instance).build();
        discovery.start();

        Assert.assertEquals(discovery.queryForNames(), Collections.singletonList("test"));

        List<ServiceInstance<String>> list = Lists.newArrayList();
        list.add(instance);
        Assert.assertEquals(discovery.queryForInstances("test"), list);
    }
    finally
    {
        CloseableUtils.closeQuietly(discovery);
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:27,代码来源:TestServiceDiscovery.java


注:本文中的org.apache.curator.x.discovery.ServiceDiscoveryBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。