question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Confusing about ManagedChannelBuilder.forAddress

See original GitHub issue

I have two grpc client.

  1. one use custom nameresolver and priority > DNSNameResolver ManagedChannelBuilder.forTarget("my-resolver:///service")
  2. one use default nameresolver. ManagedChannelBuilder.forAddress(ip, port). I expect it will call DNSNameResolver,but in fact, it call custom resolver.

this is ok

ManagedChannel channel = ManagedChannelBuilder.forAddress(ip,port)
                .nameResolverFactory(new DnsNameResolverProvider())
                .build()
ManagedChannel channel = ManagedChannelBuilder.forAddress("dns:///ip:port")
                .build()

It’s very confusing for ManagedChannel.forAddress. The behavior will be changed by register NameResolverProvider.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
voidzcycommented, Nov 20, 2020

This API use nameResolverFactory.getDefaultScheme() not dns. Sometimes it will call other NameResolver if it priority is higher than dns nameresolver

You are right. forAddress() is one of the oldest APIs of gRPC, before NameResolvers became pluggable. Yes, it uses the scheme of the resolver with the highest priority. This might be a bit surprising and we put some doc on forTarget():

We recommend libraries to specify the schema explicitly if it is known, since libraries cannot know which NameResolver will be default during runtime.

It may surprise users, but not necessarily be broken. We’d also generally recommend using priorities lower than DNS for custom resolvers to preserve the default behavior for forAddress(). But if you know what’s going on, it’s safe to use higher priorities. Anyway, it’s more recommended to use forTarget() with advanced usages such as providing custom resolvers.

0reactions
Adol1111commented, Nov 23, 2020

Yes, of course.Thank you for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

io.grpc.ManagedChannelBuilder.forAddress java code ...
Creates a {@link io.grpc.ManagedChannelBuilder} preconfigured for the emulator's port. */ private static ManagedChannelBuilder<?> ...
Read more >
Channel ManagedChannelImpl was not shut down properly
In my case, I just shutdown the channel in try,finally block: ManagedChannel channel = ManagedChannelBuilder.forAddress... try{ .
Read more >
fs2-grpc/Lobby - Gitter
Simple: implicit val sync: Sync[IO] = Sync[IO] val managedChannelStream: Stream[IO, ManagedChannel] = ManagedChannelBuilder.forAddress("127.0.0.1" ...
Read more >
ManagedChannelBuilder (grpc-all 1.51.0 API)
Provides a custom executor. static ManagedChannelBuilder<?> forAddress(String name, int port). Creates a channel with the target's ...
Read more >
Using TensorFlow models from the JVM using TensorFlow ...
val channel = ManagedChannelBuilder. ... I have been so confused with regards to TensorFlow serving and have not had luck getting this ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found