• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ConsulClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: setupWatch

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
private void setupWatch(ApplicationEventPublisher eventPublisher, GetValue getValue, String context, String aclToken) {
	ConsulClient consul = mock(ConsulClient.class);
	List<GetValue> getValues = null;

	if (getValue != null) {
		getValues = Arrays.asList(getValue);
	}

	Response<List<GetValue>> response = new Response<>(getValues, 1L, false, 1L);
	when(consul.getKVValues(eq(context), nullable(String.class), any(QueryParams.class))).thenReturn(response);

	if (StringUtils.hasText(aclToken)) {
		configProperties.setAclToken(aclToken);
	}

	LinkedHashMap<String, Long> initialIndexes = new LinkedHashMap<>();
	initialIndexes.put(context, 0L);
	ConfigWatch watch = new ConfigWatch(configProperties, consul, initialIndexes);
	watch.setApplicationEventPublisher(eventPublisher);
	watch.start();

	watch.watchConfigKeyValues();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-consul,代码行数:24,代码来源:ConfigWatchTests.java


示例2: init

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@PostConstruct
public void init() {
    consulClient = new ConsulClient(agentHost);
    executor.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            try {
                log.info("begin to load from registry");
                servicesPassing.clear();
                servicesFailing.clear();
                loadAllServiceFromConsul();
            } catch (Throwable e) {
                log.error(e.getMessage(), e);
            }
        }
    }, 0, 1, TimeUnit.MINUTES);
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:18,代码来源:ConsulRegistryRepository.java


示例3: run

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Override
public void run() {
    Lock lock = new Lock(new ConsulClient(), "lock-key", checkTtl);
    try {
        // 获取分布式互斥锁(参数含义:阻塞模式、每次尝试获取锁的间隔500ms、尝试n次)
        if (lock.lock(true, 500L, null)) {
            log.info("Thread {} start!", flag);
            // 处理业务逻辑
            Thread.sleep(new Random().nextInt(5000));
            log.info("Thread {} end!", flag);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        lock.unlock();
    }

}
 
开发者ID:dyc87112,项目名称:consul-distributed-lock,代码行数:19,代码来源:TestLock.java


示例4: beforeClass

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {

	assumeTrue(CanConnect.to(new InetSocketAddress(CONSUL_HOST, CONSUL_PORT)));

	ConsulClient client = new ConsulClient();

	Response<List<CatalogService>> response = client.getCatalogService("vault",
			QueryParams.DEFAULT);

	if (response.getValue().isEmpty()) {

		NewService service = new NewService();
		service.setAddress("localhost");
		service.setPort(8200);
		service.setId("vault");
		service.setName("vault");

		client.agentServiceRegister(service);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-vault,代码行数:22,代码来源:DiscoveryBootstrapConfigurationTests.java


示例5: setup

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Before
public void setup() {
	this.properties = new ConsulProperties();
	this.client = new ConsulClient(properties.getHost(), properties.getPort());
	this.client.setKVValue(ROOT+ APPLICATION_YML, "foo: bar\nmy.baz: ${foo}");
	this.client.setKVValue(ROOT+ APPLICATION_DEV_YML, "foo: bar-dev\nmy.baz: ${foo}");
	this.client.setKVValue(ROOT+"/master.ref", UUID.randomUUID().toString());
	this.client.setKVValue(ROOT+APP_NAME_PROPS, "foo: bar-app\nmy.baz: ${foo}");
	this.client.setKVValue(ROOT+APP_NAME_DEV_PROPS, "foo: bar-app-dev\nmy.baz: ${foo}");

	this.context = new SpringApplicationBuilder(Config.class)
			.web(false)
			.run("--spring.application.name="+ APP_NAME,
					"--spring.cloud.consul.config.prefix="+ROOT,
					"--spring.cloud.consul.config.format=FILES",
					"--spring.profiles.active=dev",
					"spring.cloud.consul.config.watch.delay=1");

	this.client = context.getBean(ConsulClient.class);
	this.properties = context.getBean(ConsulProperties.class);
	this.environment = context.getEnvironment();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-consul,代码行数:23,代码来源:ConsulPropertySourceLocatorFilesTests.java


示例6: firstCallDoesNotPublishEvent

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Test
public void firstCallDoesNotPublishEvent() {
	ApplicationEventPublisher eventPublisher = mock(ApplicationEventPublisher.class);
	configProperties.setFormat(FILES);

	GetValue getValue = new GetValue();
	String context = "/config/app.yml";
	ConsulClient consul = mock(ConsulClient.class);
	List<GetValue> getValues = Collections.singletonList(getValue);

	Response<List<GetValue>> response = new Response<>(getValues, 1L, false, 1L);
	when(consul.getKVValues(eq(context), anyString(), any(QueryParams.class))).thenReturn(response);

	ConfigWatch watch = new ConfigWatch(configProperties, consul, new LinkedHashMap<String, Long>());
	watch.setApplicationEventPublisher(eventPublisher);

	watch.watchConfigKeyValues();
	verify(eventPublisher, times(0)).publishEvent(any(RefreshEvent.class));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-consul,代码行数:20,代码来源:ConfigWatchTests.java


示例7: setup

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Before
public void setup() {
	this.properties = new ConsulProperties();
	this.client = new ConsulClient(properties.getHost(), properties.getPort());
	this.client.deleteKVValues(PREFIX);
	this.client.setKVValue(KEY1, VALUE1);
	this.client.setKVValue(KEY2, VALUE2);


	this.context = new SpringApplicationBuilder(Config.class)
			.web(false)
			.run("--SPRING_APPLICATION_NAME="+ APP_NAME,
					"--spring.cloud.consul.config.prefix="+ROOT,
					"spring.cloud.consul.config.watch.delay=10");

	this.client = context.getBean(ConsulClient.class);
	this.properties = context.getBean(ConsulProperties.class);
	this.environment = context.getEnvironment();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-consul,代码行数:20,代码来源:ConsulPropertySourceLocatorTests.java


示例8: setup

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Before
public void setup() {
	this.properties = new ConsulProperties();
	this.client = new ConsulClient(properties.getHost(), properties.getPort());
	this.client.deleteKVValues(PREFIX);
	this.client.setKVValue(KEY1, VALUE1);
	this.client.setKVValue(KEY2, VALUE2);


	this.context = new SpringApplicationBuilder(Config.class)
			.web(false)
			.run("--spring.application.name=testConsulPropertySourceLocatorAppNameCustomized",
					"--spring.cloud.consul.config.name="+CONFIG_NAME,
					"--spring.cloud.consul.config.prefix="+ROOT);

	this.client = context.getBean(ConsulClient.class);
	this.properties = context.getBean(ConsulProperties.class);
	this.environment = context.getEnvironment();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-consul,代码行数:20,代码来源:ConsulPropertySourceLocatorAppNameCustomizedTests.java


示例9: TtlScheduler

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
public TtlScheduler(ConsulClient client){
    this.client = client;
    heartbeatServiceExecutor.scheduleAtFixedRate(new ConsulHeartbeatServiceTask(), ConsulConstants.HEARTBEAT_CIRCLE,
                                                 ConsulConstants.HEARTBEAT_CIRCLE, TimeUnit.MILLISECONDS);
    heartbeatSessionExecutor.scheduleAtFixedRate(new ConsulHeartbeatSessionTask(), ConsulConstants.HEARTBEAT_CIRCLE,
                                                 ConsulConstants.HEARTBEAT_CIRCLE, TimeUnit.MILLISECONDS);
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:8,代码来源:TtlScheduler.java


示例10: newNameResolver

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Nullable
@Override
public ConsulNameResolver newNameResolver(final URI targetUri, final Attributes params) {
    if (!SCHEME.equals(targetUri.getScheme())) {
        return null;
    }

    final String targetPath = checkNotNull(targetUri.getPath(), "targetPath");
    checkArgument(targetPath.startsWith("/"));

    final String serviceName = targetPath.substring(1);
    checkArgument(serviceName.length() > 0, "serviceName");

    String consulHost = targetUri.getHost();
    if (Strings.isNullOrEmpty(consulHost)) {
        consulHost = DEFAULT_HOST;
    }

    int consulPort = targetUri.getPort();
    if (consulPort == -1) {
        consulPort = DEFAULT_PORT;
    }

    final String tag = Strings.emptyToNull(targetUri.getFragment());

    final ConsulClient consulClient = ConsulClientManager.getInstance(consulHost, consulPort);

    return new ConsulNameResolver(
            consulClient /* CatalogClient */,
            consulClient /* KeyValueClient */,
            serviceName,
            Optional.ofNullable(tag),
            GrpcUtil.TIMER_SERVICE,
            GrpcUtil.SHARED_CHANNEL_EXECUTOR
    );
}
 
开发者ID:indeedeng-alpha,项目名称:indeed-grpc-java,代码行数:37,代码来源:ConsulNameResolverProvider.java


示例11: getInstance

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
/**
 * Get or create the {@link ConsulClient} instance for the given {@code
 * host} / {@code port} / {@link TLSConfig} triplet.
 *
 * @param host The hostname of the consul instance we are attempting to
 *             connect to.
 * @param port The port of the consul instance we are attempting to connect
 *             to.
 * @param tlsConfig The TLS configuration used to secure communication with
 *                  the consul instance.
 * @return The consul client for the given triplet.
 */
public static ConsulClient getInstance(
        final String host,
        final int port,
        @Nullable final TLSConfig tlsConfig
) {
    return INSTANCE.index.computeIfAbsent(new IndexKey(host, port, tlsConfig), (key) -> {
        if (tlsConfig == null) {
            return new ConsulClient(host, port);
        } else {
            return new ConsulClient(host, port, tlsConfig);
        }
    });
}
 
开发者ID:indeedeng-alpha,项目名称:indeed-grpc-java,代码行数:26,代码来源:ConsulClientManager.java


示例12: getInstance

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Test
public void getInstance() throws Exception {
    final ConsulClient c1 = ConsulClientManager.getInstance("localhost", 8500);
    final ConsulClient c2 = ConsulClientManager.getInstance("localhost", 8500);
    final ConsulClient c3 = ConsulClientManager.getInstance("127.0.0.1", 8500);

    assertTrue(c1 == c2);
    assertFalse(c2 == c3);
}
 
开发者ID:indeedeng-alpha,项目名称:indeed-grpc-java,代码行数:10,代码来源:ConsulClientManagerTest.java


示例13: testLock

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Test
public void testLock() throws Exception  {
    ConsulClient consulClient = new ConsulClient();
    CheckTtl checkTtl = new CheckTtl("lock-1", consulClient);
    new Thread(new LockRunner(1, new CheckTtl("lock-1", consulClient))).start();
    new Thread(new LockRunner(2, new CheckTtl("lock-2", consulClient))).start();
    new Thread(new LockRunner(3, new CheckTtl("lock-3", consulClient))).start();
    new Thread(new LockRunner(4, new CheckTtl("lock-4", consulClient))).start();
    new Thread(new LockRunner(5, new CheckTtl("lock-5", consulClient))).start();
    Thread.sleep(30000L);
}
 
开发者ID:dyc87112,项目名称:consul-distributed-lock,代码行数:12,代码来源:TestLock.java


示例14: testSemaphore

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Test
public void testSemaphore() throws Exception {
    ConsulClient consulClient = new ConsulClient();
    new Thread(new SemaphoreRunner(1, new CheckTtl("semaphore-1", consulClient))).start();
    new Thread(new SemaphoreRunner(2, new CheckTtl("semaphore-2", consulClient))).start();
    new Thread(new SemaphoreRunner(3, new CheckTtl("semaphore-3", consulClient))).start();
    new Thread(new SemaphoreRunner(4, new CheckTtl("semaphore-4", consulClient))).start();
    new Thread(new SemaphoreRunner(5, new CheckTtl("semaphore-5", consulClient))).start();
    new Thread(new SemaphoreRunner(6, new CheckTtl("semaphore-6", consulClient))).start();
    new Thread(new SemaphoreRunner(7, new CheckTtl("semaphore-7", consulClient))).start();
    new Thread(new SemaphoreRunner(8, new CheckTtl("semaphore-8", consulClient))).start();
    new Thread(new SemaphoreRunner(9, new CheckTtl("semaphore-9", consulClient))).start();
    new Thread(new SemaphoreRunner(10, new CheckTtl("semaphore-10", consulClient))).start();
    Thread.sleep(50000L);
}
 
开发者ID:dyc87112,项目名称:consul-distributed-lock,代码行数:16,代码来源:TestSemaphore.java


示例15: ConsulRegistry

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
public ConsulRegistry(URL url) {
    super(url);
    if (url.isAnyHost()) {
        throw new IllegalStateException("registry address == null");
    }
    consulClient = new ConsulClient(url.getHost(), url.getPort());
}
 
开发者ID:linux-china,项目名称:dubbo3,代码行数:8,代码来源:ConsulRegistry.java


示例16: setUp

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Before
@Override
public void setUp() {
    RateLimiterErrorHandler rateLimiterErrorHandler = mock(RateLimiterErrorHandler.class);
    consulClient = mock(ConsulClient.class);
    this.setRateLimiter(new ConsulRateLimiter(rateLimiterErrorHandler, this.consulClient, this.objectMapper));
    super.setUp();
}
 
开发者ID:marcosbarbero,项目名称:spring-cloud-zuul-ratelimit,代码行数:9,代码来源:ConsulRateLimitPreFilterTest.java


示例17: activate

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Activate
public void activate(Map<String, Object> settings) {
	try {
		System.err.println("Settings: "+settings);
		String host = (String) settings.get("host.ip");
		int port = Integer.parseInt((String) settings.get("host.port"));
		wrapped = new ConsulClient(host,port);
	} catch (NumberFormatException e) {
		logger.error("Error: ", e);
	}
}
 
开发者ID:flyaruu,项目名称:tasman,代码行数:12,代码来源:ConsulOSGiClient.java


示例18: getConfiguration

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Override
protected AbstractConfiguration getConfiguration() {

  AbstractConfiguration config = ConfigurationManager.getConfigInstance();
  boolean dynamic = config.getBoolean(DYNAMIC_CONFIG, true);
  if (!dynamic) {
    return new DynamicConfiguration();
  } else {
    String appId = null;
    DeploymentContext context = ConfigurationManager.getDeploymentContext();
    appId = context.getApplicationId();
    
    if (appId == null) {
      throw new RuntimeException(
          "Archaius deployment context's applicationId not set (archaius.deployment.applicationId)");
    }

    String consulHost = config.getString(CONSUL_HOST, CONSUL_DEFAULT_HOST);
    int consulPort = config.getInt(CONSUL_PORT, 8500);
    String consulAclToken = config.getString(CONSUL_TOKEN);

    ConsulWatchedConfigurationSource configSource = new ConsulWatchedConfigurationSource(appId,
        new ConsulClient(consulHost, consulPort), 30, TimeUnit.SECONDS, consulAclToken);

    // do the first update synchronously
    try {
      configSource.runOnce();
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    }

    configSource.startAsync();

    return new DynamicWatchedConfiguration(configSource);
  }
}
 
开发者ID:irenical,项目名称:jindy,代码行数:37,代码来源:ArchaiusConsulFactory.java


示例19: beforeEach

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
@Before
public void beforeEach() {
    String config = "{" +
        "\"datacenter\": \"test-dc\"," +
        "\"log_level\": \"INFO\"," +
        "\"node_name\": \"foobar\"" +
        "}";
    consulServer = ConsulStarterBuilder.consulStarter().withCustomConfig(config).build().start();
    consulClient = new ConsulClient("127.0.0.1", consulServer.getHttpPort());
}
 
开发者ID:Netflix,项目名称:dyno,代码行数:11,代码来源:ConsulHostsSupplierTest.java


示例20: ConsulPropertySource

import com.ecwid.consul.v1.ConsulClient; //导入依赖的package包/类
public ConsulPropertySource(String context, ConsulClient source,
		ConsulConfigProperties configProperties) {
	super(context, source);
	this.context = context;
	this.configProperties = configProperties;

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-consul,代码行数:8,代码来源:ConsulPropertySource.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RoleChecker类代码示例发布时间:2022-05-21
下一篇:
Java AMCommand类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap