5
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8081)
            .usePlaintext()
            .build();

There is connection between GRPC server and client. The managed channel provide connection. When managed channel must be closed ? Or It should be open until server is shutdown? Whats the best practice about it?

Milgo
  • 2,617
  • 4
  • 22
  • 37
Ozturk
  • 569
  • 8
  • 20
  • Check this as well. https://stackoverflow.com/questions/63749113/grpc-call-channel-connection-and-http-2-lifecycle/63839453#63839453 – vins Oct 02 '20 at 04:05

1 Answers1

3

Keep the channel alive as long as you need it. That is commonly the entire application's lifetime.

Since the channel holds the connections to the servers, it should not be shutdown/recreated frequently. It's normal to create the necessarily channels early in your application's startup and then just use them as necessary.

Channels start in an idle mode which has no connections. When you perform RPCs they connect and keep those connections, but will eventually go back into idle if unused. You can configure channelBuilder.idleTimeout() to choose how aggressively they release their resources when unused.

Eric Anderson
  • 24,057
  • 5
  • 55
  • 76
  • 1
    "as long as you need it. " how? Maybe I need until server crash. Maybe I need 6 months? Its a disavantage for the system? – Ozturk Sep 30 '20 at 11:47