2

I am trying to understand the difference between ManagedChannelBuilder and NettyChannelBuilder. I came across this question but it only mentions details related to TLS configurations. Can someone explain the basic difference between the two?

According to the NettyChannelBuilder documentation, it uses Netty transport. What transport medium does the ManagedChannelBuilder use?

2 Answers2

2

ManagedChannelBuilder is an abstract class and there are concrete implementations like NettyChannelBuilder and OkHttpChannelBuilder. When you use an API like ManagedChannelBuilder.forTarget() or Grpc.newChannelBuilder() gRPC finds an appropriate concrete implementation based on your platform and returns it (normally OkHttp on Android; Netty otherwise).

The OkHttpChannelBuilder and NettyChannelBuilder APIs have more configuration options, but have no guaranteed API stability. This is because they expose options specific to the implementation and if the implementation changes (e.g., from Netty 4 to Netty 5) they may need to be changed or replaced. Because of this, you should prefer using ManagedChannelBuilder when able.

There are also concrete implementations that won't be returned by ManagedChannelBuilder.forTarget(), like InProcessChannelBuilder, CronetChannelBuilder, and AndroidChannelBuilder. These are more specialized, either not "general purpose" or require additional configuration to work.

Eric Anderson
  • 24,057
  • 5
  • 55
  • 76
1

ManagedChannelBuilder is a abstract class which define the behavior, and the NettyChannelBuilder is subclass of ManagedChannelBuilder, to determine detail of implementation,it use netty as transport; And the OkHttpChannelBuilder is another implementation which use OkHttp as transport.

When application startup, will load ManagedChannelBuilder implemetation by SPI, if you use io.grpc:grpc-netty as dependency, the NettyChannelBuilder will be used, if you don't have transport dependency, the application will start failed by io.grpc.ManagedChannelProvider$ProviderNotFoundException to ask add one of grpc-okhttp, grpc-netty, grpc-netty-shaded as dependency.

HelloWood
  • 727
  • 4
  • 13
  • Yes, I figured that out but still didn't understand what details are different between the two? While NettyChannelBuilder uses Netty as the transport medium, what transport mode does the ManagedChannelBuilder use, because we can directly use the ManagedChannelBuilder as well. – Shubham Sharma Sep 24 '21 at 03:28
  • @ShubhamSharma I add more comment for your question – HelloWood Sep 24 '21 at 06:57