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


Java Consul.Builder方法代码示例

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


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

示例1: get

import com.orbitz.consul.Consul; //导入方法依赖的package包/类
@Override
public Consul get() {

    String consulUrl = configuration.getConsulUrl();

    try {
        Consul.Builder builder = Consul.builder().withUrl(consulUrl);

        if (System.getenv(Constants.CONSUL_TOKEN_ENVIRONMENT) != null) {
            builder.withAclToken(Constants.CONSUL_TOKEN_ENVIRONMENT);
            log.info("connecting to consul with url '{}' using http token", consulUrl);
        } else {
            log.info("connecting to consul with url '{}'", consulUrl);
        }

        return builder.build();

    } catch (ConsulException e) {
        log.error("unable to connect to consul", e);
        throw new UnrecoverableException();
    }
}
 
开发者ID:pellepelster,项目名称:hivemq-consul-cluster-discovery,代码行数:23,代码来源:ConsulClientProvider.java

示例2: start

import com.orbitz.consul.Consul; //导入方法依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {

    Consul.Builder builder = Consul.builder();


    // pool because of multiple threads.
    ResteasyClientBuilder clientBuilder = new ResteasyClientBuilder();
    clientBuilder = clientBuilder.connectionPoolSize(20);

    builder.withClientBuilder(clientBuilder);
    builder.withUrl(this.url);

    try {
        this.consul = builder.build();
    } catch (Exception e) {
        throw new StartException("Failed to connect consul at " + url, e);
    }
}
 
开发者ID:wildfly-swarm-archive,项目名称:wildfly-swarm-topology-consul,代码行数:20,代码来源:ConsulService.java

示例3: start

import com.orbitz.consul.Consul; //导入方法依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {

    Consul.Builder builder = Consul.builder();


    // pool because of multiple threads.
    ResteasyClientBuilder clientBuilder = new ResteasyClientBuilder();
    clientBuilder = clientBuilder.connectionPoolSize(20);

    builder.withClientBuilder(clientBuilder);
    builder.withUrl(this.url);

    try {
        this.consul = builder.build();
    } catch (Exception e) {
        throw new StartException("Failed to connect consul at "+url, e);
    }
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:20,代码来源:ConsulService.java

示例4: createConsulClient

import com.orbitz.consul.Consul; //导入方法依赖的package包/类
public Consul createConsulClient() throws Exception {
    Consul.Builder builder = Consul.builder();
    builder.withPing(pingInstance);

    if (ObjectHelper.isNotEmpty(url)) {
        builder.withUrl(url);
    }
    if (ObjectHelper.isNotEmpty(context) && ObjectHelper.isNotEmpty(sslContextParameters)) {
        builder.withSslContext(sslContextParameters.createSSLContext(context));
    }
    if (ObjectHelper.isNotEmpty(aclToken)) {
        builder.withAclToken(aclToken);
    }
    if (requiresBasicAuthentication()) {
        builder.withBasicAuth(userName, password);
    }
    if (ObjectHelper.isNotEmpty(connectTimeoutMillis)) {
        builder.withConnectTimeoutMillis(connectTimeoutMillis);
    }
    if (ObjectHelper.isNotEmpty(readTimeoutMillis)) {
        builder.withReadTimeoutMillis(readTimeoutMillis);
    }
    if (ObjectHelper.isNotEmpty(writeTimeoutMillis)) {
        builder.withWriteTimeoutMillis(writeTimeoutMillis);
    }

    return builder.build();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:ConsulConfiguration.java

示例5: consulIsBuiltAndBound

import com.orbitz.consul.Consul; //导入方法依赖的package包/类
private MockUnit.Block consulIsBuiltAndBound(String name, Config config) {
  return unit -> {

    Config consulConfig = consulConfigWithFallback(name, config);

    Consul consul = unit.get(Consul.class);

    Consul.Builder consulBuilder = unit.mock(Consul.Builder.class);
    expect(consulBuilder.withUrl(consulConfig.getString("url"))).andReturn(consulBuilder);
    expect(consulBuilder.build()).andReturn(consul);

    unit.mockStatic(Consul.class);
    expect(Consul.builder()).andReturn(consulBuilder);

    Env env = unit.get(Env.class);
    expect(env.onStop(isA(Throwing.Runnable.class))).andReturn(env);

    //noinspection unchecked
    AnnotatedBindingBuilder<Consul> consulABB = unit.mock(AnnotatedBindingBuilder.class);
    consulABB.toInstance(consul);
    consulABB.toInstance(consul);

    Binder binder = unit.get(Binder.class);
    expect(binder.bind(Key.get(Consul.class))).andReturn(consulABB);
    expect(binder.bind(Key.get(Consul.class, Names.named(name)))).andReturn(consulABB);
  };
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:28,代码来源:ConsulbyTest.java

示例6: build

import com.orbitz.consul.Consul; //导入方法依赖的package包/类
private Consul build(final ConsulConfig cfg) {
    final Consul.Builder builder = Consul.builder();

    final HostAndPort hostAndPort = cfg.getHostAndPort();
    if (hostAndPort != null) {
        builder.withHostAndPort(cfg.getHostAndPort());
    }

    final String username = cfg.getUsernaem();
    final String password = cfg.getPassword();
    if (username != null && password != null) {
        builder.withBasicAuth(cfg.getUsernaem(), cfg.getPassword());
    }

    final URL url = cfg.getUrl();
    if (url != null) {
        builder.withUrl(cfg.getUrl());
    }

    final String token = cfg.getToken();
    if (token != null) {
        builder.withAclToken(cfg.getToken());
    }

    final Map<String, String> headers = cfg.getHeaders();
    if (!CollectionUtils.isEmpty(headers)) {
        builder.withHeaders(cfg.getHeaders());
    }

    final Long connectTimeout = cfg.getConnectTimeout();
    if (connectTimeout != null) {
        builder.withConnectTimeoutMillis(cfg.getConnectTimeout());
    }

    final Long readTimeout = cfg.getReadTimeout();
    if (readTimeout != null) {
        builder.withReadTimeoutMillis(cfg.getReadTimeout());
    }

    final Long writeTimeout = cfg.getWriteTimeout();
    if (writeTimeout != null) {
        builder.withWriteTimeoutMillis(cfg.getWriteTimeout());
    }

    return builder.build();
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:47,代码来源:ConsulModule.java

示例7: configure

import com.orbitz.consul.Consul; //导入方法依赖的package包/类
@Override
public void configure(final Env env, final Config config, final Binder binder) throws Throwable {

  Config consulConfig = config.getConfig("consul.default");
  if (!name.equals("default") && config.hasPath("consul." + name)) {
    consulConfig = config.getConfig("consul." + name).withFallback(consulConfig);
  }

  Consul.Builder consulBuilder = Consul.builder()
      .withUrl(consulConfig.getString("url"));

  if (consulBuilderConsumer != null) {
    consulBuilderConsumer.accept(consulBuilder);
  }

  Consul consul = consulBuilder.build();

  env.onStop(consul::destroy);

  env.serviceKey().generate(Consul.class, name, k -> binder.bind(k).toInstance(consul));

  if (consulConfig.hasPath("register")) {

    Config registerConfig = consulConfig.getConfig("register");

    ImmutableRegistration.Builder registrationBuilder = ImmutableRegistration.builder()
        .name(registerConfig.getString("name"))
        .address(registerConfig.getString("host"))
        .port(registerConfig.getInt("port"))
        .tags(registerConfig.getStringList("tags"))
        .id(UUID.randomUUID().toString());

    if (registerConfig.hasPath("check")) {

      Config checkConfig = registerConfig.getConfig("check");

      String http = MessageFormat.format("http://{0}:{1,number,####}{2}",
          registerConfig.getString("host"),
          registerConfig.getInt("port"),
          checkConfig.getString("path"));

      Registration.RegCheck check = Registration.RegCheck.http(http,
          checkConfig.getDuration("interval", TimeUnit.SECONDS),
          checkConfig.getDuration("timeout", TimeUnit.SECONDS));

      registrationBuilder.check(check);

      String response = checkConfig.getString("response");
      env.router().get(checkConfig.getString("path"), () -> response);
    }

    if (registrationBuilderConsumer != null) {
      registrationBuilderConsumer.accept(registrationBuilder);
    }

    Registration registration = registrationBuilder.build();

    AgentClient agentClient = consul.agentClient();
    env.onStarted(() -> agentClient.register(registration));
    env.onStop(() -> agentClient.deregister(registration.getId()));
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:63,代码来源:Consulby.java

示例8: withConsulBuilder

import com.orbitz.consul.Consul; //导入方法依赖的package包/类
/**
 * <p>
 * {@link Consul} object can be configured programmatically:
 * </p>
 *
 * <pre>{@code
 * {
 *   use(new Consulby()
 *     .withConsulBuilder(consulBuilder -> {
 *       consulBuilder.withPing(false);
 *       consulBuilder.withBasicAuth("admin", "changeme");
 *     }));
 * }
 * }</pre>
 *
 * @param consulBuilderConsumer A {@link Consumer} that accepts {@link Consul.Builder}
 * @return This {@link Consulby} to allow chaining
 */
public Consulby withConsulBuilder(final Consumer<Consul.Builder> consulBuilderConsumer) {
  this.consulBuilderConsumer = consulBuilderConsumer;
  return this;
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:23,代码来源:Consulby.java


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