Firstly to make sure we use the same terminology, what you pass to the
ManagedChannelBuilder.forTarget is not the DNS address but the domain name
or the hostname of the target you are connecting to. The hostname starts
with a DNS resolution scheme that identifies whether an in-built or a
custom name resolver gets used, and you register a custom name resolver
with the name resolver registry (guide
<https://grpc.io/docs/guides/custom-name-resolution/>). gRPC target urls
follow the format for RFC-3986 (as explained in the above guide also) which
allows the service authority to be specified between the 2nd and the 3rd
slashes after the URI scheme.
About your questions
1. It can be an anti-pattern because the gRPC allows specifying load
balancing policy in the service config encoded as Json in the txt record of
the name resolution. In-built load balancers such as pick first or
round-robin are designed to work with a single load balancing policy for
the channel. It may not be an issue if you don't have the txt records
specify any load balancing policy, so the channel uses the default
configuration for load balancing.
2. It is possible, by omitting specifying the service authority in the
target URI but have your custom name resolver handle contacting one or more
of the service authorities. However as the custom name resolution guide
explains, you may need custom load balancing policy to deal with service
configs from different name resolvers.
3. Creating multiple channels one for each DNS is the normal method anyway.
On Tuesday, May 27, 2025 at 11:36:26 AM UTC+5:30 Abhinav Kinshuk wrote:
> Different instances of the same backend I want to use in my gRPC Channel
> are hosted in different AWS regions with different DNS. I want to pass in
> all these different DNS at the time of Channel creation, probably something
> like this -
> ```
> ManagedChannelBuilder.forTarget("multi-endpoint://dns1.com;dns2.com;
> dns3.com")
> ```
>
> Then, I want to write an implementation of the NameResolver interface that
> gRPC provides, to do the name resolution individually for the three DNS.
> However, it works only if the serviceAuthority is same across all the DNS.
>
> My questions are -
>
> 1. Should I even be creating a single Channel with multiple DNS? Is it
> anti-pattern?
> 2. Is it possible to create a single Channel with multiple DNS and
> have it work when serviceAuthorities are different?
> 3. Should I create multiple Channels, one for each DNS?
>
>
> Thanks,
> Abhinav.
>
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/grpc-io/172141e9-2d2e-4fc1-b1a1-28162ae93e57n%40googlegroups.com.