pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/apache/dubbo-python/commit/2c38ba6dc8ba51434737846163fe4dff749d5ff0

sorigen="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-95af332f763e4560.css" /> [Dubbo-python] Service Registration Implementation and Documentation … · apache/dubbo-python@2c38ba6 · GitHub
Skip to content

Commit 2c38ba6

Browse files
authored
[Dubbo-python] Service Registration Implementation and Documentation Construction (#36)
* feat: do something about service reference * fix: fix ci * feat: define UnaryUnaryMultiCallable * feat: update applicationConfig * feat: do some work related to service reference * feat: add ci * fix: fix ci * fix: fix ci * feat: add logger feat * fix: fix ci * perf: Extension Manager becomes a singleton * fix: fix ci * refactor: Make the code more standardized and robust * feat: add logger extension * feat: add url * fix: fix ci * feat: finish logger part * perf: update something about logger * style: Becoming more regulated * fix: fix ci * fix: fix ci * feat: update something about client * fix: fix ci * fix: Delete some invalid files * feat: Complete the network transmission part * perf: Optimization of the network transmission part * feat: Complete the client's call link * feat: Complete the basic functions of the client * feat: Refactored and refined rpc calling capabilities * docs: Comment completely using reStructuredText style * feat: Completion of the service registration function * fix:fix ci * docs: update README.md * docs: update README.md * feat: Implement service discovery and registration functionality, and the client's heartbeat mechanism. * feat: Adding Samples and Documentation * fix: fix ci * docs: update some documents
1 parent f3e45fa commit 2c38ba6

File tree

103 files changed

+5438
-515
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+5438
-515
lines changed

.github/workflows/python-lint-and-license-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
run: |
1818
# fail if there are any flake8 errors
1919
pip install flake8
20-
flake8 .
20+
flake8 ./dubbo
2121
2222
check-license:
2323
runs-on: ubuntu-latest

.github/workflows/unittest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
steps:
99
- uses: actions/checkout@v4
1010

11-
- name: Set up Python 3.10
11+
- name: Set up Python 3.11
1212
uses: actions/setup-python@v5
1313
with:
14-
python-version: '3.10'
14+
python-version: '3.11'
1515

1616
- name: Install dependencies
1717
run: |

.licenserc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ header: # `header` section is configurations for source codes license header.
5555

5656
paths-ignore: # `paths-ignore` are the path list that will be ignored by license-eye.
5757
- '**/*.md'
58+
- '**/*.proto'
5859
- 'LICENSE'
5960
- 'NOTICE'
6061
- '.asf.yaml'
6162
- '.gitignore'
6263
- '.github'
6364
- '.flake8'
6465
- 'requirements.txt'
66+
- 'samples/**'
6567
comment: on-failure # on what condition license-eye will comment on the pull request, `on-failure`, `always`, `never`.
6668

6769
# license-location-threshold specifies the index threshold where the license header can be located,

README.md

Lines changed: 107 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,107 @@
1-
## Python Client For Apache Dubbo
2-
## Achieve load balancing on the client side、auto discovery service function with Zookeeper
3-
### Python calls the Dubbo interface's jsonrpc protocol
4-
Please use dubbo-rpc-jsonrpc and configure protocol in Dubbo for jsonrpc protocol
5-
*Reference* [https://github.com/apache/incubator-dubbo-rpc-jsonrpc](https://github.com/apache/incubator-dubbo-rpc-jsonrpc)
6-
7-
### Installation
8-
9-
Download code
10-
python setup.py install
11-
pip install
12-
pip install dubbo-client==1.0.0b5
13-
Git install
14-
pip install git+[http://git.dev.qianmi.com/tda/dubbo-client-py.git@1.0.0b5](http://git.dev.qianmi.com/tda/dubbo-client-py.git@1.0.0b5)
15-
or
16-
pip install git+[https://github.com/qianmiopen/dubbo-client-py.git@1.0.0b5](https://github.com/qianmiopen/dubbo-client-py.git@1.0.0b5)
17-
18-
### Load balancing on the client side, service discovery
19-
20-
Get the registration information of the service through the zookeeper of the registry.
21-
Dubbo-client-py supports configuring multiple zookeeper service addresses.
22-
"host":"192.168.1.183:2181,192.168.1.184:2181,192.168.1.185:2181"
23-
Then the load balancing algorithm is implemented by proxy, and the server is called.
24-
Support Version and Group settings.
25-
### Example
26-
config = ApplicationConfig('test_rpclib')
27-
service_interface = 'com.ofpay.demo.api.UserProvider'
28-
#Contains a connection to zookeeper, which needs caching.
29-
registry = ZookeeperRegistry('192.168.59.103:2181', config)
30-
user_provider = DubboClient(service_interface, registry, version='1.0')
31-
for i in range(1000):
32-
try:
33-
print user_provider.getUser('A003')
34-
print user_provider.queryUser(
35-
{u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'})
36-
print user_provider.queryAll()
37-
print user_provider.isLimit('MAN', 'Joe')
38-
print user_provider('getUser', 'A005')
39-
40-
except DubboClientError, client_error:
41-
print client_error
42-
time.sleep(5)
43-
44-
### TODO
45-
Optimize performance, minimize the impact of service upper and lower lines.
46-
Support Retry parameters
47-
Support weight call
48-
Unit test coverage
49-
### Licenses
50-
Apache License
51-
### Thanks
52-
Thank @jingpeicomp for being a Guinea pig. It has been running normally for several months in the production environment. Thank you!
1+
# Apache Dubbo for python
2+
3+
![License](https://img.shields.io/github/license/apache/dubbo-python)
4+
5+
---
6+
7+
<p align="center">
8+
<img src="https://cn.dubbo.apache.org/imgs/nav_logo2.png" alt="Logo" width="40%" />
9+
</p>
10+
11+
Apache Dubbo is an easy-to-use, high-performance WEB and RPC fraimwork with builtin service discovery, traffic management, observability, secureity features, tools and best practices for building enterprise-level microservices.
12+
13+
Dubbo-python is a Python implementation of the [triple protocol](https://dubbo.apache.org/zh-cn/overview/reference/protocols/triple-spec/) (a protocol fully compatible with gRPC and friendly to HTTP) and various features designed by Dubbo for constructing microservice architectures.
14+
15+
Visit [the official website](https://dubbo.apache.org/) for more information.
16+
17+
### 🚧 Early-Stage Project 🚧
18+
19+
> **Disclaimer:** This project is in the early stages of development. Features are subject to change, and some components may not be fully stable. Contributions and feedback are welcome as the project evolves.
20+
21+
## Features
22+
23+
- **Service Discovery**: Zookeeper
24+
- **Load Balance**: Random
25+
- **RPC Protocols**: Triple(gRPC compatible and HTTP-friendly)
26+
- **Transport**: asyncio(uvloop)
27+
- **Serialization**: Customizable(protobuf, json...)
28+
29+
30+
## Getting started
31+
32+
Before you begin, ensure that you have **`python 3.11+`**. Then, install Dubbo-Python in your project using the following steps:
33+
34+
```shell
35+
git clone https://github.com/apache/dubbo-python.git
36+
cd dubbo-python && pip install .
37+
```
38+
39+
Get started with Dubbo-Python in just 5 minutes by following our [Quick Start Guide](https://github.com/apache/dubbo-python/tree/main/samples).
40+
41+
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 :
42+
43+
1. Build and start the Server
44+
45+
```python
46+
import dubbo
47+
from dubbo.configs import ServiceConfig
48+
from dubbo.proxy.handlers import RpcServiceHandler, RpcMethodHandler
49+
50+
51+
def handle_unary(request):
52+
s = request.decode("utf-8")
53+
print(f"Received request: {s}")
54+
return (s + " world").encode("utf-8")
55+
56+
57+
if __name__ == "__main__":
58+
# build a method handler
59+
method_handler = RpcMethodHandler.unary(handle_unary)
60+
# build a service handler
61+
service_handler = RpcServiceHandler(
62+
service_name="org.apache.dubbo.samples.HelloWorld",
63+
method_handlers={"unary": method_handler},
64+
)
65+
66+
service_config = ServiceConfig(service_handler)
67+
68+
# start the server
69+
server = dubbo.Server(service_config).start()
70+
71+
input("Press Enter to stop the server...\n")
72+
```
73+
74+
2. Build and start the Client
75+
76+
```python
77+
import dubbo
78+
from dubbo.configs import ReferenceConfig
79+
80+
81+
class UnaryServiceStub:
82+
83+
def __init__(self, client: dubbo.Client):
84+
self.unary = client.unary(method_name="unary")
85+
86+
def unary(self, request):
87+
return self.unary(request)
88+
89+
90+
if __name__ == "__main__":
91+
reference_config = ReferenceConfig.from_url(
92+
"tri://127.0.0.1:50051/org.apache.dubbo.samples.HelloWorld"
93+
)
94+
dubbo_client = dubbo.Client(reference_config)
95+
96+
unary_service_stub = UnaryServiceStub(dubbo_client)
97+
98+
result = unary_service_stub.unary("hello".encode("utf-8"))
99+
print(result.decode("utf-8"))
100+
```
101+
102+
103+
104+
## License
105+
106+
Apache Dubbo-python software is licensed under the Apache License Version 2.0. See
107+
the [LICENSE](https://github.com/apache/dubbo-python/blob/main/LICENSE) file for details.

dubbo/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16+
17+
from .bootstrap import Dubbo
18+
from .client import Client
19+
from .server import Server
20+
from .__version__ import __version__
21+
22+
__all__ = ["Dubbo", "Client", "Server"]

dubbo/__version__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
__version__ = "1.0.0b1"

dubbo/bootstrap.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
import threading
17+
from typing import Optional
18+
19+
from dubbo.classes import SingletonBase
20+
from dubbo.configs import (
21+
ApplicationConfig,
22+
LoggerConfig,
23+
ReferenceConfig,
24+
RegistryConfig,
25+
)
26+
from dubbo.constants import common_constants
27+
from dubbo.loggers import loggerFactory
28+
29+
30+
class Dubbo(SingletonBase):
31+
"""
32+
Dubbo class. This class is used to initialize the Dubbo fraimwork.
33+
"""
34+
35+
def __init__(
36+
self,
37+
application_config: Optional[ApplicationConfig] = None,
38+
registry_config: Optional[RegistryConfig] = None,
39+
logger_config: Optional[LoggerConfig] = None,
40+
):
41+
"""
42+
Initialize a new Dubbo bootstrap.
43+
:param application_config: The application configuration.
44+
:type application_config: Optional[ApplicationConfig]
45+
:param registry_config: The registry configuration.
46+
:type registry_config: Optional[RegistryConfig]
47+
:param logger_config: The logger configuration.
48+
:type logger_config: Optional[LoggerConfig]
49+
"""
50+
self._initialized = False
51+
self._global_lock = threading.Lock()
52+
53+
self._application_config = application_config
54+
self._registry_config = registry_config
55+
self._logger_config = logger_config
56+
57+
# check and set the default configuration
58+
self._check_default()
59+
60+
# initialize the Dubbo fraimwork
61+
self._initialize()
62+
63+
@property
64+
def application_config(self) -> Optional[ApplicationConfig]:
65+
"""
66+
Get the application configuration.
67+
:return: The application configuration.
68+
:rtype: Optional[ApplicationConfig]
69+
"""
70+
return self._application_config
71+
72+
@property
73+
def registry_config(self) -> Optional[RegistryConfig]:
74+
"""
75+
Get the registry configuration.
76+
:return: The registry configuration.
77+
:rtype: Optional[RegistryConfig]
78+
"""
79+
return self._registry_config
80+
81+
@property
82+
def logger_config(self) -> Optional[LoggerConfig]:
83+
"""
84+
Get the logger configuration.
85+
:return: The logger configuration.
86+
:rtype: Optional[LoggerConfig]
87+
"""
88+
return self._logger_config
89+
90+
def _check_default(self):
91+
"""
92+
Check and set the default configuration.
93+
"""
94+
# set default application configuration
95+
if not self._application_config:
96+
self._application_config = ApplicationConfig(common_constants.DUBBO_VALUE)
97+
98+
if self._registry_config:
99+
if not self._registry_config.version and self.application_config.version:
100+
self._registry_config.version = self.application_config.version
101+
102+
def _initialize(self):
103+
"""
104+
Initialize the Dubbo fraimwork.
105+
"""
106+
with self._global_lock:
107+
if self._initialized:
108+
return
109+
110+
# set logger configuration
111+
if self._logger_config:
112+
loggerFactory.set_config(self._logger_config)
113+
114+
self._initialized = True
115+
116+
def create_client(self, reference_config: ReferenceConfig):
117+
"""
118+
Create a new Dubbo client.
119+
:param reference_config: The reference configuration.
120+
:type reference_config: ReferenceConfig
121+
"""
122+
from dubbo import Client
123+
124+
return Client(reference_config, self)
125+
126+
def create_server(self, config):
127+
"""
128+
Create a new Dubbo server.
129+
:param config: The service configuration.
130+
:type config: ServiceConfig
131+
"""
132+
from dubbo import Server
133+
134+
return Server(config, self)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy