commit
f63b51be86
114 changed files with 1500 additions and 308 deletions
@ -1,6 +1,14 @@ |
|||||||
mergeable: |
mergeable: |
||||||
pull_requests: |
pull_requests: |
||||||
label: |
label: |
||||||
must_include: |
or: |
||||||
regex: "release notes: yes|release notes: no" |
- and: |
||||||
message: "Add release notes yes/no label. For yes, add lang label" |
- must_include: |
||||||
|
regex: 'release notes: yes' |
||||||
|
message: 'Please include release note: yes' |
||||||
|
- must_include: |
||||||
|
regex: '^lang\/' |
||||||
|
message: 'Please include a language label' |
||||||
|
- must_include: |
||||||
|
regex: 'release notes: no' |
||||||
|
message: 'Please include release note: no' |
||||||
|
@ -0,0 +1,61 @@ |
|||||||
|
# gRPC Python Server Reflection |
||||||
|
|
||||||
|
This document shows how to use gRPC Server Reflection in gRPC Python. |
||||||
|
Please see [C++ Server Reflection Tutorial](../server_reflection_tutorial.md) |
||||||
|
for general information and more examples how to use server reflection. |
||||||
|
|
||||||
|
## Enable server reflection in Python servers |
||||||
|
|
||||||
|
gRPC Python Server Reflection is an add-on library. |
||||||
|
To use it, first install the [grpcio-reflection](https://pypi.org/project/grpcio-reflection/) |
||||||
|
PyPI package into your project. |
||||||
|
|
||||||
|
Note that with Python you need to manually register the service |
||||||
|
descriptors with the reflection service implementation when creating a server |
||||||
|
(this isn't necessary with e.g. C++ or Java) |
||||||
|
```python |
||||||
|
# add the following import statement to use server reflection |
||||||
|
from grpc_reflection.v1alpha import reflection |
||||||
|
# ... |
||||||
|
def serve(): |
||||||
|
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) |
||||||
|
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server) |
||||||
|
# the reflection service will be aware of "Greeter" and "ServerReflection" services. |
||||||
|
SERVICE_NAMES = ( |
||||||
|
helloworld_pb2.DESCRIPTOR.services_by_name['Greeter'].full_name, |
||||||
|
reflection.SERVICE_NAME, |
||||||
|
) |
||||||
|
reflection.enable_server_reflection(SERVICE_NAMES, server) |
||||||
|
server.add_insecure_port('[::]:50051') |
||||||
|
server.start() |
||||||
|
``` |
||||||
|
|
||||||
|
Please see |
||||||
|
[greeter_server_with_reflection.py](https://github.com/grpc/grpc/blob/master/examples/python/helloworld/greeter_server_with_reflection.py) |
||||||
|
in the examples directory for the full example, which extends the gRPC [Python |
||||||
|
`Greeter` example](https://github.com/grpc/tree/master/examples/python/helloworld) on a |
||||||
|
reflection-enabled server. |
||||||
|
|
||||||
|
After starting the server, you can verify that the server reflection |
||||||
|
is working properly by using the [`grpc_cli` command line |
||||||
|
tool](https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md): |
||||||
|
|
||||||
|
```sh |
||||||
|
$ grpc_cli ls localhost:50051 |
||||||
|
``` |
||||||
|
|
||||||
|
output: |
||||||
|
```sh |
||||||
|
grpc.reflection.v1alpha.ServerReflection |
||||||
|
helloworld.Greeter |
||||||
|
``` |
||||||
|
|
||||||
|
For more examples and instructions how to use the `grpc_cli` tool, |
||||||
|
please refer to the [`grpc_cli` documentation](../command_line_tool.md) |
||||||
|
and the [C++ Server Reflection Tutorial](../server_reflection_tutorial.md). |
||||||
|
|
||||||
|
## Additional Resources |
||||||
|
|
||||||
|
The [Server Reflection Protocol](../server-reflection.md) provides detailed |
||||||
|
information about how the server reflection works and describes the server reflection |
||||||
|
protocol in detail. |
@ -0,0 +1,52 @@ |
|||||||
|
# Copyright 2018 The gRPC Authors |
||||||
|
# |
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
# you may not use this file except in compliance with the License. |
||||||
|
# You may obtain a copy of the License at |
||||||
|
# |
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
# |
||||||
|
# Unless required by applicable law or agreed to in writing, software |
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
# See the License for the specific language governing permissions and |
||||||
|
# limitations under the License. |
||||||
|
"""The reflection-enabled version of gRPC helloworld.Greeter server.""" |
||||||
|
|
||||||
|
from concurrent import futures |
||||||
|
import time |
||||||
|
|
||||||
|
import grpc |
||||||
|
from grpc_reflection.v1alpha import reflection |
||||||
|
|
||||||
|
import helloworld_pb2 |
||||||
|
import helloworld_pb2_grpc |
||||||
|
|
||||||
|
_ONE_DAY_IN_SECONDS = 60 * 60 * 24 |
||||||
|
|
||||||
|
|
||||||
|
class Greeter(helloworld_pb2_grpc.GreeterServicer): |
||||||
|
|
||||||
|
def SayHello(self, request, context): |
||||||
|
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name) |
||||||
|
|
||||||
|
|
||||||
|
def serve(): |
||||||
|
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) |
||||||
|
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server) |
||||||
|
SERVICE_NAMES = ( |
||||||
|
helloworld_pb2.DESCRIPTOR.services_by_name['Greeter'].full_name, |
||||||
|
reflection.SERVICE_NAME, |
||||||
|
) |
||||||
|
reflection.enable_server_reflection(SERVICE_NAMES, server) |
||||||
|
server.add_insecure_port('[::]:50051') |
||||||
|
server.start() |
||||||
|
try: |
||||||
|
while True: |
||||||
|
time.sleep(_ONE_DAY_IN_SECONDS) |
||||||
|
except KeyboardInterrupt: |
||||||
|
server.stop(0) |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__': |
||||||
|
serve() |
@ -0,0 +1,36 @@ |
|||||||
|
#!/usr/bin/env python |
||||||
|
# Copyright 2015 gRPC authors. |
||||||
|
# |
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
# you may not use this file except in compliance with the License. |
||||||
|
# You may obtain a copy of the License at |
||||||
|
# |
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
# |
||||||
|
# Unless required by applicable law or agreed to in writing, software |
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
# See the License for the specific language governing permissions and |
||||||
|
# limitations under the License. |
||||||
|
|
||||||
|
import os |
||||||
|
import subprocess |
||||||
|
import sys |
||||||
|
|
||||||
|
# The c-ares test suite doesn't get ran regularly on Windows, but |
||||||
|
# this script provides a way to run a lot of the tests manually. |
||||||
|
_MSBUILD_CONFIG = os.environ['CONFIG'] |
||||||
|
os.chdir(os.path.join('..', '..', os.getcwd())) |
||||||
|
# This port is arbitrary, but it needs to be available. |
||||||
|
_DNS_SERVER_PORT = 15353 |
||||||
|
|
||||||
|
subprocess.call([ |
||||||
|
sys.executable, |
||||||
|
'test\\cpp\\naming\\resolver_component_tests_runner.py', |
||||||
|
'--test_bin_path', 'cmake\\build\\%s\\resolver_component_test.exe' % _MSBUILD_CONFIG, |
||||||
|
'--dns_server_bin_path', 'test\\cpp\\naming\\utils\\dns_server.py', |
||||||
|
'--records_config_path', 'test\\cpp\\naming\\resolver_test_record_groups.yaml', |
||||||
|
'--dns_server_port', str(_DNS_SERVER_PORT), |
||||||
|
'--dns_resolver_bin_path', 'test\\cpp\\naming\\utils\\dns_resolver.py', |
||||||
|
'--tcp_connect_bin_path', 'test\\cpp\\naming\\utils\\tcp_connect.py', |
||||||
|
]) |
@ -1 +1 @@ |
|||||||
Subproject commit b5fbb742af122b565925987e65c08957739976a7 |
Subproject commit 48cb18e5c419ddd23d9badcfe4e9df7bde1979b2 |
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue