examples: Allow passing target and simplify lifecycle#6630
examples: Allow passing target and simplify lifecycle#6630ejona86 merged 1 commit intogrpc:masterfrom
Conversation
The target can be provided on the command line to avoid needing to recompile the example just to change where the server is located. We use a target instead of addresses as that is the approach we have wanted to encourage for a while since it allows choosing alternative name resolvers. We typically encourage injecting Channels, not ManagedChannels, which has the added benefit of simplifying the example. Less indirection makes for a better example. Swapping to target string could be done to examples-tls and examples-gauth as well, but it would be much more invasive to the tls example and the gauth example would need proper testing after the change.
|
CC @donnadionne, @menghanl, this is a general cleanup of the helloworld example, but it does add more argument parsing. See the README added in #6631 to see how this will look to users in Java. C++'s plan of just adding a flag to set the target string sounds fine. Go may need to copy the main.go from the helloworld example, since it can't as easily do the trick I did to reuse the main() function. |
|
For the example to work with |
|
@sanjaypujare, yes. See #6631 |
|
Seems the README.md must be changed. |
|
@dapengzhang0, why must the readme be changed? |
|
Never mind, I though the hostname and port are present in the command line arguments in README, they are not. |
|
Note: After the next release this will require a smallish change to the tutorial since it has snippets of the routeguide that changed here. The quickstart is not impacted. |
The target can be provided on the command line to avoid needing to recompile
the example just to change where the server is located. We use a target instead
of addresses as that is the approach we have wanted to encourage for a while
since it allows choosing alternative name resolvers.
We typically encourage injecting Channels, not ManagedChannels, which has the
added benefit of simplifying the example. Less indirection makes for a better
example.
Swapping to target string could be done to examples-tls and examples-gauth as
well, but it would be much more invasive to the tls example and the gauth
example would need proper testing after the change.
These are things that I've wanted for a while, but now the target change is
necessary for the xds example and the rest sort of falls out of that.