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

Java HttpClientBuilder类代码示例

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

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



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

示例1: HttpClient

import io.reactivex.netty.protocol.http.client.HttpClientBuilder; //导入依赖的package包/类
public HttpClient(Collection<String> nodes) {
    // searchShard
    // search template

    List<io.reactivex.netty.protocol.http.client.HttpClient<ByteBuf, ByteBuf>> clientsTemp = new ArrayList<>();
    // expect something like "http://%s:%d"
    for (String node : nodes) {
        String[] next = node.split(":");
        // indices admin
        String host = next[1].substring(2); // remove the // of http://
        int port = Integer.parseInt(next[2]);
        HttpClientBuilder<ByteBuf, ByteBuf> clientBuilder = RxNetty.newHttpClientBuilder(host, port);
        clientBuilder.config(new RxClient.ClientConfig.Builder().readTimeout(timeOut, MILLISECONDS).build());
        clientBuilder.withMaxConnections(maxConnections);
        clientsTemp.add(clientBuilder.build());
        logger.info("adding host {}:{}", host, port);
    }
    this.clients = new SnapshotableCopyOnWriteArray<>(clientsTemp);

    clientSupplier = new RoundRobinSupplier<>(clients);

    this.httpAdminClient = new HttpAdminClient(clientSupplier);
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:24,代码来源:HttpClient.java


示例2: httpClientBuilder

import io.reactivex.netty.protocol.http.client.HttpClientBuilder; //导入依赖的package包/类
private HttpClientBuilder<ByteBuf, ByteBuf> httpClientBuilder() {
    HttpClientBuilder<ByteBuf, ByteBuf> builder = RxNetty
            .<ByteBuf, ByteBuf>newHttpClientBuilder(this.serviceEndpoint.getHost(), this.serviceEndpoint.getPort())
            .withSslEngineFactory(DefaultFactories.trustAll()).withMaxConnections(connectionPolicy.getMaxPoolSize())
            .withIdleConnectionsTimeoutMillis(this.connectionPolicy.getIdleConnectionTimeout() * 1000);

    ClientConfig config = new ClientConfig.Builder()
            .readTimeout(connectionPolicy.getRequestTimeout(), TimeUnit.SECONDS).build();
    return builder.config(config);
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:11,代码来源:RxDocumentClientImpl.java


示例3: ZmonMonitoringSystem

import io.reactivex.netty.protocol.http.client.HttpClientBuilder; //导入依赖的package包/类
public ZmonMonitoringSystem(ZmonConfiguration configuration)
{
    HttpClientBuilder<ByteBuf, ByteBuf> builder = RxNetty.newHttpClientBuilder(configuration.getHost(), configuration.getPort());
    if (configuration.isSecure())
    {
        builder.withSslEngineFactory(DefaultFactories.trustAll());
    }
    rxNetty = builder.build();
    this.configuration = configuration;
}
 
开发者ID:OskarKjellin,项目名称:vizceral-hystrix,代码行数:11,代码来源:ZmonMonitoringSystem.java


示例4: HystrixReader

import io.reactivex.netty.protocol.http.client.HttpClientBuilder; //导入依赖的package包/类
/**
 * Creates a new hystrix reader.
 *
 * @param configuration The configuration to use.
 * @param cluster       The cluster to read from.
 */
public HystrixReader(Configuration configuration, String cluster)
{
    this.configuration = configuration;
    this.cluster = cluster;
    HttpClientBuilder<ByteBuf, ServerSentEvent> builder = RxNetty.newHttpClientBuilder(configuration.getTurbineHost(), configuration.getTurbinePort());
    builder.pipelineConfigurator(PipelineConfigurators.clientSseConfigurator());
    if (configuration.isSecure())
    {
        builder.withSslEngineFactory(DefaultFactories.trustAll());
    }
    rxNetty = builder.build();
}
 
开发者ID:OskarKjellin,项目名称:vizceral-hystrix,代码行数:19,代码来源:HystrixReader.java


示例5: getOrCreateRxClient

import io.reactivex.netty.protocol.http.client.HttpClientBuilder; //导入依赖的package包/类
@Override
protected HttpClient<I, ServerSentEvent> getOrCreateRxClient(Server server) {
    HttpClientBuilder<I, ServerSentEvent> clientBuilder =
            new HttpClientBuilder<I, ServerSentEvent>(server.getHost(), server.getPort()).pipelineConfigurator(pipelineConfigurator);
    int requestConnectTimeout = getProperty(IClientConfigKey.Keys.ConnectTimeout, null, DefaultClientConfigImpl.DEFAULT_CONNECT_TIMEOUT);
    RxClient.ClientConfig rxClientConfig = new HttpClientConfig.Builder().build();
    
    HttpClient<I, ServerSentEvent> client = clientBuilder.channelOption(
            ChannelOption.CONNECT_TIMEOUT_MILLIS, requestConnectTimeout).config(rxClientConfig).build();
    return client;
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:12,代码来源:SSEClient.java


示例6: WSClient

import io.reactivex.netty.protocol.http.client.HttpClientBuilder; //导入依赖的package包/类
public WSClient(String host, int port, int firstStep, int stepSize, int stepDuration, String query) {
    this.host = host;
    this.port = port;
    this.firstStep = firstStep;
    this.stepSize = stepSize;
    this.stepDuration = stepDuration;
    this.query = query;

    System.out.println("Starting client with hostname: " + host + "  port: " + port + "  first-step: " + firstStep + "  step-size: " + stepSize + "  step-duration: " + stepDuration + "s  query: " + query);

    httpClient = new HttpClientBuilder<ByteBuf, ByteBuf>(this.host, this.port)
            .withMaxConnections(15000)
            .config(new HttpClient.HttpClientConfig.Builder().readTimeout(1, TimeUnit.MINUTES).build())
            .build();
    stats = new ConnectionPoolMetricListener();
    httpClient.subscribe(stats);

    client = httpClient.submit(HttpClientRequest.createGet(this.query))
            .flatMap(response -> {
                if (response.getStatus().code() == 200) {
                    counter.increment(CounterEvent.SUCCESS);
                } else {
                    counter.increment(CounterEvent.HTTP_ERROR);
                }
                return response.getContent().doOnNext(bb -> {
                    counter.add(CounterEvent.BYTES, bb.readableBytes());
                });
            }).doOnError((t) -> {
                if (t instanceof PoolExhaustedException) {
                    counter.increment(CounterEvent.POOL_EXHAUSTED);
                } else {
                    counter.increment(CounterEvent.NETTY_ERROR);
                }
            });
}
 
开发者ID:Netflix-Skunkworks,项目名称:WSPerfLab,代码行数:36,代码来源:WSClient.java


示例7: TestRouteBasic

import io.reactivex.netty.protocol.http.client.HttpClientBuilder; //导入依赖的package包/类
public TestRouteBasic(String backendHost, int backendPort) {
    host = backendHost;
    port = backendPort;
    client = new HttpClientBuilder<ByteBuf, ByteBuf>(host, port)
            .withMaxConnections(10000)
            .config(new HttpClient.HttpClientConfig.Builder().readTimeout(1, TimeUnit.MINUTES).build())
            .build();
    stats = new ConnectionPoolMetricListener();
    client.subscribe(stats);
}
 
开发者ID:Netflix-Skunkworks,项目名称:WSPerfLab,代码行数:11,代码来源:TestRouteBasic.java


示例8: executeSingle

import io.reactivex.netty.protocol.http.client.HttpClientBuilder; //导入依赖的package包/类
/**
 * Execute an HTTP request.
 *
 * @param server Server to send the request to.
 * @param req    Request to execute.
 * @return Observable with the response of the request.
 */
private static Observable<HttpClientResponse<ByteBuf>>
executeSingle(Server server, HttpClientRequest<ByteBuf> req) {
    HttpClient.HttpClientConfig config = new HttpClient.HttpClientConfig.Builder()
            .readTimeout(READ_TIMEOUT_MS, TimeUnit.MILLISECONDS)
            .userAgent(USER_AGENT)
            .build();


    HttpClientBuilder<ByteBuf, ByteBuf> builder =
            RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder(server.host(), server.port())
                    .pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpClientConfigurator())
                    .config(config)
                    .channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MS);

    if (server.isSecure()) {
        builder.withSslEngineFactory(DefaultFactories.trustAll());
    }

    final HttpClient<ByteBuf, ByteBuf> client = builder.build();
    return client.submit(req)
            .doOnNext(new Action1<HttpClientResponse<ByteBuf>>() {
                @Override
                public void call(HttpClientResponse<ByteBuf> res) {
                    LOGGER.debug("Got response: {}", res.getStatus().code());
                }
            })
            .doOnError(new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    LOGGER.info("Error sending metrics: {}/{}",
                            throwable.getClass().getSimpleName(),
                            throwable.getMessage());
                }
            })
            .doOnTerminate(new Action0() {
                @Override
                public void call() {
                    client.shutdown();
                }
            });
}
 
开发者ID:dmuino,项目名称:atlas-oss-plugin,代码行数:49,代码来源:RxHttp.java


示例9: createRxClient

import io.reactivex.netty.protocol.http.client.HttpClientBuilder; //导入依赖的package包/类
@Override
protected HttpClient<I, O> createRxClient(Server server) {
    HttpClientBuilder<I, O> clientBuilder;
    if (requestIdProvider != null) {
        clientBuilder = RxContexts.<I, O>newHttpClientBuilder(server.getHost(), server.getPort(), 
                requestIdProvider, RxContexts.DEFAULT_CORRELATOR, pipelineConfigurator);
    } else {
        clientBuilder = RxContexts.<I, O>newHttpClientBuilder(server.getHost(), server.getPort(), 
                RxContexts.DEFAULT_CORRELATOR, pipelineConfigurator);
    }
    Integer connectTimeout = getProperty(IClientConfigKey.Keys.ConnectTimeout,  null, DefaultClientConfigImpl.DEFAULT_CONNECT_TIMEOUT);
    Integer readTimeout    = getProperty(IClientConfigKey.Keys.ReadTimeout,     null, DefaultClientConfigImpl.DEFAULT_READ_TIMEOUT);
    Boolean followRedirect = getProperty(IClientConfigKey.Keys.FollowRedirects, null, null);
    HttpClientConfig.Builder builder = new HttpClientConfig.Builder().readTimeout(readTimeout, TimeUnit.MILLISECONDS);
    if (followRedirect != null) {
        builder.setFollowRedirect(followRedirect);
    }
    clientBuilder
            .channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout)
            .config(builder.build());
    if (isPoolEnabled()) {
        clientBuilder
            .withConnectionPoolLimitStrategy(poolStrategy)
            .withIdleConnectionsTimeoutMillis(idleConnectionEvictionMills)
            .withPoolIdleCleanupScheduler(poolCleanerScheduler);
    } 
    else {
        clientBuilder
            .withNoConnectionPooling();
    }
    
    if (sslContextFactory != null) {
        try {
            SSLEngineFactory myFactory = new DefaultFactories.SSLContextBasedFactory(sslContextFactory.getSSLContext()) {
                @Override
                public SSLEngine createSSLEngine(ByteBufAllocator allocator) {
                    SSLEngine myEngine = super.createSSLEngine(allocator);
                    myEngine.setUseClientMode(true);
                    return myEngine;
                }
            };

            clientBuilder.withSslEngineFactory(myFactory);
        } catch (ClientSslSocketFactoryException e) {
            throw new RuntimeException(e);
        }
    }
    return clientBuilder.build();
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:50,代码来源:LoadBalancingHttpClient.java


示例10: createHttpClient

import io.reactivex.netty.protocol.http.client.HttpClientBuilder; //导入依赖的package包/类
public static HttpClient<ByteBuf, ByteBuf> createHttpClient(String host, int port) {
    return new HttpClientBuilder<ByteBuf, ByteBuf>(host, port).build();
}
 
开发者ID:allenxwang,项目名称:RxNetty,代码行数:4,代码来源:RxNetty.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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