Skip to content

Instantly share code, notes, and snippets.

@kgoralski
Created December 12, 2018 20:33
Show Gist options
  • Select an option

  • Save kgoralski/f830c610d9e90aa6d5de20d2f690770e to your computer and use it in GitHub Desktop.

Select an option

Save kgoralski/f830c610d9e90aa6d5de20d2f690770e to your computer and use it in GitHub Desktop.
By default, HttpClient participates in the global Reactor Netty resources held in reactor.netty.http.HttpResources, including event loop threads and a connection pool. This is the recommended mode, since fixed, shared resources are preferred for event loop concurrency. In this mode global resources remain active until the process exits.

ReactorClientHttpConnector
ClientHttpConnector

https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-client-builder

https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java

https://github.com/spring-projects/spring-framework/blob/master/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java

public ReactorNettyTcpClient(String host, int port, ReactorNettyCodec<P> codec) {
		Assert.notNull(host, "host is required");
		Assert.notNull(codec, "ReactorNettyCodec is required");

		this.channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
		this.loopResources = LoopResources.create("tcp-client-loop");
		this.poolResources = ConnectionProvider.elastic("tcp-client-pool");
		this.codec = codec;

		this.tcpClient = TcpClient.create(this.poolResources)
				.host(host).port(port)
				.runOn(this.loopResources, false)
				.doOnConnected(conn -> this.channelGroup.add(conn.channel()));
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment