@@ -29,76 +29,91 @@ Visit [the official website](https://dubbo.apache.org/) for more information.
2929- ** Serialization** : Customizable(protobuf, json...)
3030
3131
32- ## Getting started
3332
34- Before you begin, ensure that you have ** ` python 3.11+ ` ** . Then, install Dubbo-Python in your project using the following steps:
33+ ## Installation
34+
35+ Before you start, make sure you have ** ` python 3.11+ ` ** installed.
3536
36- ``` shell
37- git clone https://github.com/apache/dubbo-python.git
38- cd dubbo-python && pip install .
39- ```
37+ 1 . Install from source
38+
39+ ``` sh
40+ git clone https://github.com/apache/dubbo-python.git
41+ cd dubbo-python && pip install .
42+ ```
43+
44+
45+ ## Getting started
4046
41- Get started with Dubbo-Python in just 5 minutes by following our [ Quick Start Guide] ( https://github.com/apache/dubbo-python/tree/main/samples ) .
47+ Get up and running with Dubbo-Python in just 5 minutes by following our [ Quick Start Guide] ( https://github.com/apache/dubbo-python/tree/main/samples ) .
4248
43- It's as simple as the following code snippet. With just a few lines of code, you can launch a fully functional point-to-point RPC service :
49+ It's as simple as the code snippet below . With just a few lines of code, you can launch a fully functional point-to-point RPC service:
4450
45- 1 . Build and start the Server
51+ 1 . Build and start the server
4652
4753 ``` python
4854 import dubbo
4955 from dubbo.configs import ServiceConfig
50- from dubbo.proxy.handlers import RpcServiceHandler, RpcMethodHandler
56+ from dubbo.proxy.handlers import RpcMethodHandler, RpcServiceHandler
5157
5258
53- def handle_unary ( request ) :
54- s = request.decode( " utf-8 " )
55- print (f " Received request : { s } " )
56- return (s + " world " ).encode( " utf-8 " )
59+ class UnaryServiceServicer :
60+ def say_hello ( self , message : bytes ) -> bytes :
61+ print (f " Received message from client : { message } " )
62+ return b " Hello from server "
5763
5864
59- if __name__ == " __main__ " :
65+ def build_service_handler () :
6066 # build a method handler
61- method_handler = RpcMethodHandler.unary(handle_unary)
67+ method_handler = RpcMethodHandler.unary(
68+ method = UnaryServiceServicer().say_hello, method_name = " unary"
69+ )
6270 # build a service handler
6371 service_handler = RpcServiceHandler(
6472 service_name = " org.apache.dubbo.samples.HelloWorld" ,
65- method_handlers = { " unary " : method_handler} ,
73+ method_handlers = [ method_handler] ,
6674 )
75+ return service_handler
6776
68- service_config = ServiceConfig(service_handler)
6977
78+ if __name__ == " __main__" :
79+ # build service config
80+ service_handler = build_service_handler()
81+ service_config = ServiceConfig(
82+ service_handler = service_handler, host = " 127.0.0.1" , port = 50051
83+ )
7084 # start the server
7185 server = dubbo.Server(service_config).start()
7286
7387 input (" Press Enter to stop the server...\n " )
7488 ```
7589
76- 2 . Build and start the Client
90+ 1 . Build and start the Client
7791
7892 ``` python
7993 import dubbo
8094 from dubbo.configs import ReferenceConfig
8195
8296
8397 class UnaryServiceStub :
84-
8598 def __init__ (self , client : dubbo.Client):
8699 self .unary = client.unary(method_name = " unary" )
87100
88- def unary (self , request ) :
89- return self .unary(request )
101+ def say_hello (self , message : bytes ) -> bytes :
102+ return self .unary(message )
90103
91104
92105 if __name__ == " __main__" :
106+ # Create a client
93107 reference_config = ReferenceConfig.from_url(
94108 " tri://127.0.0.1:50051/org.apache.dubbo.samples.HelloWorld"
95109 )
96110 dubbo_client = dubbo.Client(reference_config)
97-
98111 unary_service_stub = UnaryServiceStub(dubbo_client)
99112
100- result = unary_service_stub.unary(" hello" .encode(" utf-8" ))
101- print (result.decode(" utf-8" ))
113+ # Call the remote method
114+ result = unary_service_stub.say_hello(b " Hello from client" )
115+ print (result)
116+
102117 ```
103118
104119
0 commit comments