Merge pull request #165 from wilsonwen/master
Fix grpc example after API changed
This commit is contained in:
commit
d80141b1f7
|
|
@ -46,7 +46,11 @@ a greeting in a single `HelloReply`. This is the simplest type of RPC you
|
||||||
can specify in gRPC.
|
can specify in gRPC.
|
||||||
|
|
||||||
```
|
```
|
||||||
syntax = "proto2";
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option java_package = "io.grpc.examples";
|
||||||
|
|
||||||
|
package helloworld;
|
||||||
|
|
||||||
// The greeting service definition.
|
// The greeting service definition.
|
||||||
service Greeter {
|
service Greeter {
|
||||||
|
|
@ -56,12 +60,12 @@ service Greeter {
|
||||||
|
|
||||||
// The request message containing the user's name.
|
// The request message containing the user's name.
|
||||||
message HelloRequest {
|
message HelloRequest {
|
||||||
optional string name = 1;
|
string name = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The response message containing the greetings
|
// The response message containing the greetings
|
||||||
message HelloReply {
|
message HelloReply {
|
||||||
optional string message = 1;
|
string message = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
@ -83,7 +87,7 @@ $ ./run_codegen.sh
|
||||||
Which internally invokes the proto-compiler as:
|
Which internally invokes the proto-compiler as:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ protoc -I . --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` helloworld.proto
|
$ protoc -I ../../protos --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` ../../protos/helloworld.proto
|
||||||
```
|
```
|
||||||
|
|
||||||
Optionally, you can just skip the code generation step as the generated python module has already
|
Optionally, you can just skip the code generation step as the generated python module has already
|
||||||
|
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
// Copyright 2015, Google Inc.
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without
|
|
||||||
// modification, are permitted provided that the following conditions are
|
|
||||||
// met:
|
|
||||||
//
|
|
||||||
// * Redistributions of source code must retain the above copyright
|
|
||||||
// notice, this list of conditions and the following disclaimer.
|
|
||||||
// * Redistributions in binary form must reproduce the above
|
|
||||||
// copyright notice, this list of conditions and the following disclaimer
|
|
||||||
// in the documentation and/or other materials provided with the
|
|
||||||
// distribution.
|
|
||||||
// * Neither the name of Google Inc. nor the names of its
|
|
||||||
// contributors may be used to endorse or promote products derived from
|
|
||||||
// this software without specific prior written permission.
|
|
||||||
//
|
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
syntax = "proto2";
|
|
||||||
|
|
||||||
//TODO: see https://github.com/grpc/grpc/issues/814
|
|
||||||
//package examples;
|
|
||||||
|
|
||||||
// The greeting service definition.
|
|
||||||
service Greeter {
|
|
||||||
// Sends a greeting
|
|
||||||
rpc SayHello (HelloRequest) returns (HelloReply) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The request message containing the user's name.
|
|
||||||
message HelloRequest {
|
|
||||||
optional string name = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The response message containing the greetings
|
|
||||||
message HelloReply {
|
|
||||||
optional string message = 1;
|
|
||||||
}
|
|
||||||
|
|
@ -1,151 +0,0 @@
|
||||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
||||||
# source: helloworld.proto
|
|
||||||
|
|
||||||
import sys
|
|
||||||
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
|
||||||
from google.protobuf import descriptor as _descriptor
|
|
||||||
from google.protobuf import message as _message
|
|
||||||
from google.protobuf import reflection as _reflection
|
|
||||||
from google.protobuf import symbol_database as _symbol_database
|
|
||||||
from google.protobuf import descriptor_pb2
|
|
||||||
# @@protoc_insertion_point(imports)
|
|
||||||
|
|
||||||
_sym_db = _symbol_database.Default()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTOR = _descriptor.FileDescriptor(
|
|
||||||
name='helloworld.proto',
|
|
||||||
package='',
|
|
||||||
serialized_pb=_b('\n\x10helloworld.proto\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t23\n\x07Greeter\x12(\n\x08SayHello\x12\r.HelloRequest\x1a\x0b.HelloReply\"\x00')
|
|
||||||
)
|
|
||||||
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_HELLOREQUEST = _descriptor.Descriptor(
|
|
||||||
name='HelloRequest',
|
|
||||||
full_name='HelloRequest',
|
|
||||||
filename=None,
|
|
||||||
file=DESCRIPTOR,
|
|
||||||
containing_type=None,
|
|
||||||
fields=[
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='name', full_name='HelloRequest.name', index=0,
|
|
||||||
number=1, type=9, cpp_type=9, label=1,
|
|
||||||
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
options=None),
|
|
||||||
],
|
|
||||||
extensions=[
|
|
||||||
],
|
|
||||||
nested_types=[],
|
|
||||||
enum_types=[
|
|
||||||
],
|
|
||||||
options=None,
|
|
||||||
is_extendable=False,
|
|
||||||
extension_ranges=[],
|
|
||||||
oneofs=[
|
|
||||||
],
|
|
||||||
serialized_start=20,
|
|
||||||
serialized_end=48,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
_HELLOREPLY = _descriptor.Descriptor(
|
|
||||||
name='HelloReply',
|
|
||||||
full_name='HelloReply',
|
|
||||||
filename=None,
|
|
||||||
file=DESCRIPTOR,
|
|
||||||
containing_type=None,
|
|
||||||
fields=[
|
|
||||||
_descriptor.FieldDescriptor(
|
|
||||||
name='message', full_name='HelloReply.message', index=0,
|
|
||||||
number=1, type=9, cpp_type=9, label=1,
|
|
||||||
has_default_value=False, default_value=_b("").decode('utf-8'),
|
|
||||||
message_type=None, enum_type=None, containing_type=None,
|
|
||||||
is_extension=False, extension_scope=None,
|
|
||||||
options=None),
|
|
||||||
],
|
|
||||||
extensions=[
|
|
||||||
],
|
|
||||||
nested_types=[],
|
|
||||||
enum_types=[
|
|
||||||
],
|
|
||||||
options=None,
|
|
||||||
is_extendable=False,
|
|
||||||
extension_ranges=[],
|
|
||||||
oneofs=[
|
|
||||||
],
|
|
||||||
serialized_start=50,
|
|
||||||
serialized_end=79,
|
|
||||||
)
|
|
||||||
|
|
||||||
DESCRIPTOR.message_types_by_name['HelloRequest'] = _HELLOREQUEST
|
|
||||||
DESCRIPTOR.message_types_by_name['HelloReply'] = _HELLOREPLY
|
|
||||||
|
|
||||||
HelloRequest = _reflection.GeneratedProtocolMessageType('HelloRequest', (_message.Message,), dict(
|
|
||||||
DESCRIPTOR = _HELLOREQUEST,
|
|
||||||
__module__ = 'helloworld_pb2'
|
|
||||||
# @@protoc_insertion_point(class_scope:HelloRequest)
|
|
||||||
))
|
|
||||||
_sym_db.RegisterMessage(HelloRequest)
|
|
||||||
|
|
||||||
HelloReply = _reflection.GeneratedProtocolMessageType('HelloReply', (_message.Message,), dict(
|
|
||||||
DESCRIPTOR = _HELLOREPLY,
|
|
||||||
__module__ = 'helloworld_pb2'
|
|
||||||
# @@protoc_insertion_point(class_scope:HelloReply)
|
|
||||||
))
|
|
||||||
_sym_db.RegisterMessage(HelloReply)
|
|
||||||
|
|
||||||
|
|
||||||
import abc
|
|
||||||
from grpc.early_adopter import implementations
|
|
||||||
from grpc.early_adopter import utilities
|
|
||||||
class EarlyAdopterGreeterServicer(object):
|
|
||||||
"""<fill me in later!>"""
|
|
||||||
__metaclass__ = abc.ABCMeta
|
|
||||||
@abc.abstractmethod
|
|
||||||
def SayHello(self, request, context):
|
|
||||||
raise NotImplementedError()
|
|
||||||
class EarlyAdopterGreeterServer(object):
|
|
||||||
"""<fill me in later!>"""
|
|
||||||
__metaclass__ = abc.ABCMeta
|
|
||||||
@abc.abstractmethod
|
|
||||||
def start(self):
|
|
||||||
raise NotImplementedError()
|
|
||||||
@abc.abstractmethod
|
|
||||||
def stop(self):
|
|
||||||
raise NotImplementedError()
|
|
||||||
class EarlyAdopterGreeterStub(object):
|
|
||||||
"""<fill me in later!>"""
|
|
||||||
__metaclass__ = abc.ABCMeta
|
|
||||||
@abc.abstractmethod
|
|
||||||
def SayHello(self, request):
|
|
||||||
raise NotImplementedError()
|
|
||||||
SayHello.async = None
|
|
||||||
def early_adopter_create_Greeter_server(servicer, port, root_certificates, key_chain_pairs):
|
|
||||||
import helloworld_pb2
|
|
||||||
import helloworld_pb2
|
|
||||||
method_service_descriptions = {
|
|
||||||
"SayHello": utilities.unary_unary_service_description(
|
|
||||||
servicer.SayHello,
|
|
||||||
helloworld_pb2.HelloRequest.FromString,
|
|
||||||
helloworld_pb2.HelloReply.SerializeToString,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
return implementations.secure_server(method_service_descriptions, port, root_certificates, key_chain_pairs)
|
|
||||||
def early_adopter_create_Greeter_stub(host, port):
|
|
||||||
import helloworld_pb2
|
|
||||||
import helloworld_pb2
|
|
||||||
method_invocation_descriptions = {
|
|
||||||
"SayHello": utilities.unary_unary_invocation_description(
|
|
||||||
helloworld_pb2.HelloRequest.SerializeToString,
|
|
||||||
helloworld_pb2.HelloReply.FromString,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
return implementations.insecure_stub(method_invocation_descriptions, host, port)
|
|
||||||
# @@protoc_insertion_point(module_scope)
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Runs the protoc with gRPC plugin to generate protocol messages and gRPC stubs.
|
# Runs the protoc with gRPC plugin to generate protocol messages and gRPC stubs.
|
||||||
protoc -I . --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` helloworld.proto
|
protoc -I ../../protos --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` ../../protos/helloworld.proto
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue