Skip to content

Commit 58acec9

Browse files
committed
docs: update some samples
1 parent 8bdba77 commit 58acec9

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

dubbo/constants/common_constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858

5959
RPC_TYPE_KEY = "rpc-type"
6060

61-
CALL_KEY = "call"
6261
METHOD_DESCRIPTOR_KEY = "method-descriptor"
6362

6463
LOADBALANCE_KEY = "loadbalance"

samples/registry/zookeeper/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import dubbo
1818
from dubbo.configs import ReferenceConfig, RegistryConfig
19-
from samples.data import greeter_pb2
19+
from samples.proto import greeter_pb2
2020

2121

2222
class GreeterServiceStub:
@@ -42,6 +42,6 @@ def say_hello(self, request):
4242

4343
stub = GreeterServiceStub(dubbo_client)
4444

45-
result = stub.say_hello(greeter_pb2.GreeterRequest(name="hello"))
45+
result = stub.say_hello(greeter_pb2.GreeterRequest(name="dubbo-python"))
4646

4747
print(result.message)

samples/registry/zookeeper/server.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616
import dubbo
1717
from dubbo.configs import RegistryConfig, ServiceConfig
1818
from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler
19-
from samples.data import greeter_pb2
19+
from samples.proto import greeter_pb2
2020

2121

22-
def say_hello(request):
23-
print(f"Received request: {request}")
24-
return greeter_pb2.GreeterReply(message=f"{request.name} Dubbo!")
22+
class GreeterServiceServicer:
23+
def say_hello(self, request):
24+
print(f"Received request: {request.name}")
25+
return greeter_pb2.GreeterReply(message=f"Hello, {request.name}!")
2526

2627

27-
if __name__ == "__main__":
28+
def build_server_handler():
2829
# build a method handler
2930
method_handler = RpcMethodHandler.unary(
30-
say_hello,
31+
GreeterServiceServicer().say_hello,
3132
method_name="sayHello",
3233
request_deserializer=greeter_pb2.GreeterRequest.FromString,
3334
response_serializer=greeter_pb2.GreeterReply.SerializeToString,
@@ -37,10 +38,15 @@ def say_hello(request):
3738
service_name="org.apache.dubbo.samples.data.Greeter",
3839
method_handlers=[method_handler],
3940
)
41+
return service_handler
42+
4043

44+
if __name__ == "__main__":
4145
registry_config = RegistryConfig.from_url("zookeeper://127.0.0.1:2181")
4246
bootstrap = dubbo.Dubbo(registry_config=registry_config)
4347

48+
# build a service config
49+
service_handler = build_server_handler()
4450
service_config = ServiceConfig(service_handler)
4551

4652
# start the server

0 commit comments

Comments
 (0)