用python构建微服务
pymicroservice的Python项目详细描述
**pymicroservice**framework
==
[![构建状态](https://travis-ci.org/vladcalin/pymicroservice.svg?branch=master)(https://travis ci.org/vladcalin/pymicroservice)
[![文档状态](https://readthedocs.org/projects/pymicroservice/badge/?版本=最新](http://pymicroservice.readthedocs.io/en/latest/?徽章=最新)
[![PYPI版本](https://badge.fury.io/py/pymicroservice.svg)(https://badge.fury.io/py/pymicroservice)
[![覆盖状态](https://coveralls.io/repos/github/vladcalin/pymicroservice/badge.svg?branch=master)(https://coveralls.io/github/vladcalin/pymicroservice?branch=master)
尽管这种体系结构越来越流行,但有一些工具可以帮助
个人构建这样的系统。目前的替代方案是使用[nameko](https://github.com/nameko/nameko)
,或者构建一个类似于微服务的web应用程序。我开始开发这个框架是为了提供一个工具来轻松地创建和管理这样的系统,并且能够专门从事某个角色,比如it实体管理,数据存储或只是计算。
方法调用是异步处理的。如果您不了解python中的异步
编程,我建议您阅读
`tornado documentation<;http://www.tornadoweb.org/en/stable/>;` `.
中的一些单词,尽管您不需要了解所有的协程和事件循环理论,理解
引擎盖下发生的事情*
installation
----
要安装此库,请运行命令
pip install pymicroservice
,或者从源代码安装它
git clone https://github.com/vladcalin/pymicroservice.git
cd pymicroservice
python setup.py install
要运行测试,请运行命令
example basic usage
---------
将以下代码写入“hello庠world庠service.py”文件:
``python
from py microservice.core.microservice import pymicroservice,\
public庠方法,私有api方法
class hello world service(pymicroservice):
name=“hello.world.service”
host=“127.0.0.1”
port=5000
@public方法def say_private戋u hello(self,name):
返回“this is secret:hello{}”。格式(name)
def api戋u token戋u有效(self,api-token):
return api-token=“hello-world-token”
为了与之交互,我们必须使用jsonrpc协议如下:
```
post/api
{
“jsonrpc”:“2.0”、
“method”:“say_hello”、
“params”:{
“name”:“world”
}、
“id”:1
````
{
“error”:null,
“id”:1,
“response”:“hello world”
}
````
要访问私有方法,我们必须在http
请求中包含一个值为“hello\u world”的“x-api-token”头,因此
方法“api_token_is_valid``将返回“true`”。
此库提供了一个类,您可以通过该类与各种服务进行交互:
`` python
print(client.name)““service.hello.world”
打印(客户端.方法.说“你好(“world”)。“你好世界”
`````
``````````
<协作
>欢迎任何协作。是的请随意创建新问题、提出建议、打开请求请求。
更改
----
请参阅[更改.md](changes.md)
==
[![构建状态](https://travis-ci.org/vladcalin/pymicroservice.svg?branch=master)(https://travis ci.org/vladcalin/pymicroservice)
[![文档状态](https://readthedocs.org/projects/pymicroservice/badge/?版本=最新](http://pymicroservice.readthedocs.io/en/latest/?徽章=最新)
[![PYPI版本](https://badge.fury.io/py/pymicroservice.svg)(https://badge.fury.io/py/pymicroservice)
[![覆盖状态](https://coveralls.io/repos/github/vladcalin/pymicroservice/badge.svg?branch=master)(https://coveralls.io/github/vladcalin/pymicroservice?branch=master)
尽管这种体系结构越来越流行,但有一些工具可以帮助
个人构建这样的系统。目前的替代方案是使用[nameko](https://github.com/nameko/nameko)
,或者构建一个类似于微服务的web应用程序。我开始开发这个框架是为了提供一个工具来轻松地创建和管理这样的系统,并且能够专门从事某个角色,比如it实体管理,数据存储或只是计算。
方法调用是异步处理的。如果您不了解python中的异步
编程,我建议您阅读
`tornado documentation<;http://www.tornadoweb.org/en/stable/>;` `.
中的一些单词,尽管您不需要了解所有的协程和事件循环理论,理解
引擎盖下发生的事情*
installation
----
要安装此库,请运行命令
pip install pymicroservice
,或者从源代码安装它
git clone https://github.com/vladcalin/pymicroservice.git
cd pymicroservice
python setup.py install
要运行测试,请运行命令
example basic usage
---------
将以下代码写入“hello庠world庠service.py”文件:
``python
from py microservice.core.microservice import pymicroservice,\
public庠方法,私有api方法
class hello world service(pymicroservice):
name=“hello.world.service”
host=“127.0.0.1”
port=5000
@public方法def say_private戋u hello(self,name):
返回“this is secret:hello{}”。格式(name)
def api戋u token戋u有效(self,api-token):
return api-token=“hello-world-token”
为了与之交互,我们必须使用jsonrpc协议如下:
```
post/api
{
“jsonrpc”:“2.0”、
“method”:“say_hello”、
“params”:{
“name”:“world”
}、
“id”:1
````
{
“error”:null,
“id”:1,
“response”:“hello world”
}
````
要访问私有方法,我们必须在http
请求中包含一个值为“hello\u world”的“x-api-token”头,因此
方法“api_token_is_valid``将返回“true`”。
此库提供了一个类,您可以通过该类与各种服务进行交互:
`` python
打印(客户端.方法.说“你好(“world”)。“你好世界”
`````
``````````
<协作
>欢迎任何协作。是的请随意创建新问题、提出建议、打开请求请求。
更改
----
请参阅[更改.md](changes.md)