reactor.netty.http.client.HttpClient.from()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中reactor.netty.http.client.HttpClient.from()方法的一些代码示例,展示了HttpClient.from()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.from()方法的具体详情如下:
包路径:reactor.netty.http.client.HttpClient
类名称:HttpClient
方法名:from

HttpClient.from介绍

[英]Prepare a pooled HttpClient
[中]准备一个池式HttpClient

代码示例

代码示例来源:origin: spring-projects/spring-data-elasticsearch

private static WebClientProvider getWebClientProvider(ClientConfiguration clientConfiguration) {
  Duration connectTimeout = clientConfiguration.getConnectTimeout();
  Duration soTimeout = clientConfiguration.getSocketTimeout();
  TcpClient tcpClient = TcpClient.create();
  if (!connectTimeout.isNegative()) {
    tcpClient = tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.toIntExact(connectTimeout.toMillis()));
  }
  if (!soTimeout.isNegative()) {
    tcpClient = tcpClient.doOnConnected(connection -> connection //
        .addHandlerLast(new ReadTimeoutHandler(soTimeout.toMillis(), TimeUnit.MILLISECONDS))
        .addHandlerLast(new WriteTimeoutHandler(soTimeout.toMillis(), TimeUnit.MILLISECONDS)));
  }
  String scheme = "http";
  HttpClient httpClient = HttpClient.from(tcpClient);
  if (clientConfiguration.useSsl()) {
    httpClient = httpClient.secure(sslConfig -> {
      Optional<SSLContext> sslContext = clientConfiguration.getSslContext();
      sslContext.ifPresent(it -> sslConfig.sslContext(new JdkSslContext(it, true, ClientAuth.NONE)));
    });
    scheme = "https";
  }
  ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
  WebClientProvider provider = WebClientProvider.create(scheme, connector);
  return provider.withDefaultHeaders(clientConfiguration.getDefaultHeaders());
}

代码示例来源:origin: rsocket/rsocket-java

/**
 * Creates a new instance
 *
 * @param client the {@link TcpClient} to use
 * @return a new instance
 * @throws NullPointerException if {@code client} or {@code path} is {@code null}
 */
public static WebsocketClientTransport create(TcpClient client) {
 Objects.requireNonNull(client, "client must not be null");
 return create(HttpClient.from(client), "/");
}

代码示例来源:origin: rsocket/rsocket-java

/**
 * Creates a new instance
 *
 * @param uri the URI to connect to
 * @return a new instance
 * @throws NullPointerException if {@code uri} is {@code null}
 */
public static WebsocketClientTransport create(URI uri) {
 Objects.requireNonNull(uri, "uri must not be null");
 TcpClient client = createClient(uri);
 return create(HttpClient.from(client), uri.getPath());
}

代码示例来源:origin: io.rsocket/rsocket-transport-netty

/**
 * Creates a new instance
 *
 * @param client the {@link TcpClient} to use
 * @return a new instance
 * @throws NullPointerException if {@code client} or {@code path} is {@code null}
 */
public static WebsocketClientTransport create(TcpClient client) {
 Objects.requireNonNull(client, "client must not be null");
 return create(HttpClient.from(client), "/");
}

代码示例来源:origin: io.rsocket/rsocket-transport-netty

/**
 * Creates a new instance
 *
 * @param uri the URI to connect to
 * @return a new instance
 * @throws NullPointerException if {@code uri} is {@code null}
 */
public static WebsocketClientTransport create(URI uri) {
 Objects.requireNonNull(uri, "uri must not be null");
 TcpClient client = createClient(uri);
 return create(HttpClient.from(client), uri.getPath());
}

相关文章