And the rest of helloworld

pull/21504/head
Richard Belleville 5 years ago
parent 4b3ad3f750
commit e5e218381a
  1. 7
      examples/python/helloworld/greeter_client_with_options.py
  2. 11
      examples/python/helloworld/greeter_server_with_reflection.py

@ -18,8 +18,7 @@ import logging
import grpc
import helloworld_pb2
import helloworld_pb2_grpc
protos, services = grpc.protos_and_services("helloworld.proto")
def run():
@ -33,11 +32,11 @@ def run():
options=[('grpc.lb_policy_name', 'pick_first'),
('grpc.enable_retries', 0), ('grpc.keepalive_timeout_ms',
10000)]) as channel:
stub = helloworld_pb2_grpc.GreeterStub(channel)
stub = services.GreeterStub(channel)
# Timeout in seconds.
# Please refer gRPC Python documents for more detail. https://grpc.io/grpc/python/grpc.html
response = stub.SayHello(
helloworld_pb2.HelloRequest(name='you'), timeout=10)
protos.HelloRequest(name='you'), timeout=10)
print("Greeter client received: " + response.message)

@ -19,21 +19,20 @@ import logging
import grpc
from grpc_reflection.v1alpha import reflection
import helloworld_pb2
import helloworld_pb2_grpc
protos, services = grpc.protos_and_services("helloworld.proto")
class Greeter(helloworld_pb2_grpc.GreeterServicer):
class Greeter(services.GreeterServicer):
def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
return protos.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)
services.add_GreeterServicer_to_server(Greeter(), server)
SERVICE_NAMES = (
helloworld_pb2.DESCRIPTOR.services_by_name['Greeter'].full_name,
protos.DESCRIPTOR.services_by_name['Greeter'].full_name,
reflection.SERVICE_NAME,
)
reflection.enable_server_reflection(SERVICE_NAMES, server)

Loading…
Cancel
Save