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


Java ServiceDiscovery.start方法代码示例

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


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

示例1: getGeolocationServiceProvider

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的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

示例2: buildServiceDiscoveryWith

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的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

示例3: testBasic

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的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

示例4: testCleaning

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
@Test
public void testCleaning() 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();
        discovery.unregisterService(instance);

        Assert.assertEquals(((ServiceDiscoveryImpl)discovery).debugServicesQty(), 0);
    }
    finally
    {
        CloseableUtils.closeQuietly(discovery);
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:24,代码来源:TestServiceDiscovery.java

示例5: main

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	// This method is scaffolding to get the example up and running
	TestingServer server = new TestingServer();
	CuratorFramework client = null;
	ServiceDiscovery<InstanceDetails> serviceDiscovery = null;
	Map<String, ServiceProvider<InstanceDetails>> providers = Maps.newHashMap();
	try {
		client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3));
		client.start();
		JsonInstanceSerializer<InstanceDetails> serializer = new JsonInstanceSerializer<InstanceDetails>(InstanceDetails.class);
		serviceDiscovery = ServiceDiscoveryBuilder.builder(InstanceDetails.class).client(client).basePath(PATH).serializer(serializer).build();
		serviceDiscovery.start();
		processCommands(serviceDiscovery, providers, client);
	} finally {
		for (ServiceProvider<InstanceDetails> cache : providers.values()) {
			CloseableUtils.closeQuietly(cache);
		}
		CloseableUtils.closeQuietly(serviceDiscovery);
		CloseableUtils.closeQuietly(client);
		CloseableUtils.closeQuietly(server);
	}
}
 
开发者ID:smallnest,项目名称:ZKRecipesByExample,代码行数:23,代码来源:DiscoveryExample.java

示例6: startServiceDiscovery

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
private void startServiceDiscovery() {

        //already chrooted so use /
        String basePath = "/";

        ServiceDiscovery<String> serviceDiscovery = ServiceDiscoveryBuilder
                .builder(String.class)
                .client(Preconditions.checkNotNull(curatorFrameworkRef.get(), "curatorFramework should not be null at this point"))
                .basePath(basePath)
                .build();

        try {
            serviceDiscovery.start();
            //push to the top of the queue to ensure this gets closed before the curator framework else it
            //won't work as it has no client
            closeables.push(serviceDiscovery);
            boolean wasSet = serviceDiscoveryRef.compareAndSet(null, serviceDiscovery);
            if (!wasSet) {
                LOGGER.error("Attempt to set serviceDiscoveryRef when already set");
            } else {
                LOGGER.info("Successfully started ServiceDiscovery on path " + basePath);
            }

        } catch (Exception e) {
            throw new RuntimeException(String.format("Error starting ServiceDiscovery with base path %s", basePath), e);
        }
    }
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:28,代码来源:ServiceDiscoveryManager.java

示例7: createServiceDiscovery

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
private void createServiceDiscovery() {
    LOGGER.info("Starting Curator client using Zookeeper at '{}'...", zookeeper);
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeper, retryPolicy);
    client.start();

    try {
        LOGGER.info("Setting up instance for '{}' service, running on '{}:{}'...", name, ipAddress, port);
        ServiceInstance<String> instance = ServiceInstance.<String>builder()
                .serviceType(ServiceType.PERMANENT)
                .name(name)
                .address(ipAddress)
                .port(port)
                .build();

        ServiceDiscovery serviceDiscovery = ServiceDiscoveryBuilder
                .builder(String.class)
                .client(client)
                .basePath("stroom-services")
                .thisInstance(instance)
                .build();

        serviceDiscovery.start();
        LOGGER.info("Service instance created successfully!");
    } catch (Exception e){
        LOGGER.error("Service instance creation failed! ", e);
    }
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:29,代码来源:StroomServiceRegisterer.java

示例8: getServiceDiscovery

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
/**
 * Gets the discovery.
 *
 * @param basePath         - Registration path
 * @param curatorFramework - Curator
 * @return the discovery
 * @throws Exception the exception
 */
protected static ServiceDiscovery<MetaData> getServiceDiscovery(CuratorFramework curatorFramework, String basePath)
        throws Exception {

    new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());

    JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<MetaData>(MetaData.class); // Payload Serializer
    ServiceDiscovery<MetaData> serviceDiscovery = ServiceDiscoveryBuilder.builder(MetaData.class).client(curatorFramework).basePath(basePath).serializer(serializer).build(); // Service Discovery
    serviceDiscovery.start();

    return serviceDiscovery;
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:20,代码来源:ServiceUtil.java

示例9: getServiceCacheBuilder

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
/**
 * Gets the discovery.
 *
 * @param basePath         - Registration path
 * @param curatorFramework - Curator
 * @return the ServiceCacheBuilder
 * @throws Exception the exception
 */
protected static ServiceDiscovery<MetaData> getServiceCacheBuilder(CuratorFramework curatorFramework, String basePath)
        throws Exception {

    new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());

    JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<MetaData>(MetaData.class); // Payload Serializer
    ServiceDiscovery<MetaData> serviceDiscovery = ServiceDiscoveryBuilder.builder(MetaData.class).client(curatorFramework).basePath(basePath).serializer(serializer).build(); // Service Discovery
    serviceDiscovery.start();

    return serviceDiscovery;
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:20,代码来源:ServiceUtil.java

示例10: main

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
    // This method is scaffolding to get the example up and running

    TestingServer                                   server = new TestingServer();
    CuratorFramework                                client = null;
    ServiceDiscovery<InstanceDetails>               serviceDiscovery = null;
    Map<String, ServiceProvider<InstanceDetails>>   providers = Maps.newHashMap();
    try
    {
        client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3));
        client.start();

        JsonInstanceSerializer<InstanceDetails> serializer = new JsonInstanceSerializer<InstanceDetails>(InstanceDetails.class);
        serviceDiscovery = ServiceDiscoveryBuilder.builder(InstanceDetails.class).client(client).basePath(PATH).serializer(serializer).build();
        serviceDiscovery.start();

        processCommands(serviceDiscovery, providers, client);
    }
    finally
    {
        for ( ServiceProvider<InstanceDetails> cache : providers.values() )
        {
            CloseableUtils.closeQuietly(cache);
        }

        CloseableUtils.closeQuietly(serviceDiscovery);
        CloseableUtils.closeQuietly(client);
        CloseableUtils.closeQuietly(server);
    }
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:32,代码来源:DiscoveryExample.java

示例11: main

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);

  CuratorFramework client = CuratorFrameworkFactory.newClient("10.4.7.220:2181", new
          RetryNTimes(5, 1000));
  client.start();

  ServiceDiscovery<String> discovery = ServiceDiscoveryBuilder.<String>builder(String.class)
          .basePath("/discovery")
          .client(client)
          .build();
  discovery.start();

  ServiceProvider provider = discovery.serviceProviderBuilder().serviceName("hoho")
          .build();
  provider.start();

  executorService.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      try {
        ServiceInstance instance = provider.getInstance();
        System.out.println(instance);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }, 1, 1, TimeUnit.SECONDS);

}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:31,代码来源:Main.java

示例12: testBasic

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
@Test
public void testBasic() throws Exception
{
    List<Closeable> closeables = Lists.newArrayList();
    try
    {
        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
        closeables.add(client);
        client.start();

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

        ServiceProvider<String> provider = discovery.serviceProviderBuilder().serviceName("test").build();
        closeables.add(provider);
        provider.start();

        Assert.assertEquals(provider.getInstance(), instance);

        List<ServiceInstance<String>> list = Lists.newArrayList();
        list.add(instance);
        Assert.assertEquals(provider.getAllInstances(), list);
    }
    finally
    {
        Collections.reverse(closeables);
        for ( Closeable c : closeables )
        {
            CloseableUtils.closeQuietly(c);
        }
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:35,代码来源:TestServiceProvider.java

示例13: testDisabledInstance

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
@Test
public void testDisabledInstance() throws Exception
{
    List<Closeable> closeables = Lists.newArrayList();
    try
    {
        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
        closeables.add(client);
        client.start();

        ServiceInstance<String> instance = ServiceInstance.<String>builder().payload("thing").name("test").port(10064).enabled(false).build();
        InstanceSerializer<String> serializer = new JsonInstanceSerializer<>(String.class, false);
        ServiceDiscovery<String> discovery = ServiceDiscoveryBuilder.builder(String.class).serializer(serializer).basePath("/test").client(client).thisInstance(instance).build();
        closeables.add(discovery);
        discovery.start();

        ServiceProvider<String> provider = discovery.serviceProviderBuilder().serviceName("test").build();
        closeables.add(provider);
        provider.start();

        Assert.assertEquals(provider.getInstance(), null);
        Assert.assertTrue(provider.getAllInstances().isEmpty(), "Disabled instance still appears available via service provider");
    }
    finally
    {
        Collections.reverse(closeables);
        for ( Closeable c : closeables )
        {
            CloseableUtils.closeQuietly(c);
        }
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:33,代码来源:TestServiceProvider.java

示例14: testCrashedInstance

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
@Test
public void testCrashedInstance() throws Exception
{
    CuratorFramework client = null;
    ServiceDiscovery<String> discovery = null;
    try
    {
        Timing timing = new Timing();

        client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
        client.start();

        ServiceInstance<String> instance = ServiceInstance.<String>builder().payload("thing").name("test").port(10064).build();
        discovery = new ServiceDiscoveryImpl<String>(client, "/test", new JsonInstanceSerializer<String>(String.class), instance, false);
        discovery.start();

        Assert.assertEquals(discovery.queryForInstances("test").size(), 1);

        KillSession2.kill(client.getZookeeperClient().getZooKeeper());
        Thread.sleep(timing.multiple(1.5).session());

        Assert.assertEquals(discovery.queryForInstances("test").size(), 1);
    }
    finally
    {
        CloseableUtils.closeQuietly(discovery);
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:30,代码来源:TestServiceDiscovery.java

示例15: testNoServerOnStart

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
@Test
public void testNoServerOnStart() throws Exception
{
    Timing timing = new Timing();
    server.stop();

    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();

        server.restart();
        timing.sleepABit();
        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,代码行数:32,代码来源:TestServiceDiscovery.java


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