示例#1
0
    def SayHello(self, request, context):
        for key, value in context.invocation_metadata():
            print('Received initial metadata: key=%s value=%s' % (key, value))

        context.set_trailing_metadata((
            ('checksum-bin', b'I agree'),
            ('retry', 'false'),
        ))
        return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
示例#2
0
 def SayHello(self, request, context):
     with self._lock:
         if request.name in self._greeted:
             rich_status = create_greet_limit_exceed_error_status(
                 request.name)
             context.abort_with_status(rpc_status.to_status(rich_status))
         else:
             self._greeted.add(request.name)
     return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
示例#3
0
 def SayHello(self, request, context):
     if self._should_suppress_compression():
         context.set_response_compression(grpc.Compression.NoCompression)
     return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
示例#4
0
 def SayHello(self, request, context):
     return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
示例#5
0
 def SayHello(self, request, context):
     if random.random() < self._failure_rate:
         context.abort(grpc.StatusCode.UNAVAILABLE,
                       'Randomly injected failure.')
     return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
示例#6
0
 def SayHello(self, request: helloworld_pb2.HelloRequest,
              context: grpc.ServicerContext) -> helloworld_pb2.HelloReply:
     return helloworld_pb2.HelloReply(
         message=f"Hello {request.name} from {self._hostname}!")