hprose 介绍

hprose 是 High-Performance Remote  Object Service  Engine 的简称(高性能远程对象服务引擎库)。 它是以RPC的方式对外提供服务的,hprose可以做到跨语言:

场景(可以实现):

         1. 使用python 编写hprose server端

          2. 使用golang编写hprose client端

hprose官方支持很多种语言

官方网站:  https://hprose.com/

安装(官方文档写的很清楚):

  1.  python 环境:

pip install hprose

 2. golang 环境:

go get -u -v github.com/hprose/hprose-golang

下面展示一下python 写server端,golang写 client端。

python server:

import hprose

def send(data):
    return data + " server test"

def main():
    server = hprose.HttpServer(port = 8081)
    server.addFunction(send)
    server.start()

if __name__ == '__main__':
    main()

golang client(同步的,golang还提供异步的):

ackage main

import (
	"fmt"

	grpc "github.com/hprose/hprose-golang/rpc"
)

func init() {

}

type SendST struct {
	Send func(string) string `name:"send"`
}

func main() {
	client := grpc.NewHTTPClient("http://127.0.0.1:8081")
	var send *SendST
	client.UseService(&send)
	fmt.Println(send.Send("client send hello"))

}

注意:  NewHTTPClient参数 "http://127.0.0.1:8081"  不要写成 "http://127.0.0.1:8081/"

output:

          client send hello server test

当然也可以使用golang写server端, python写client端,使用hprose也确实很容易构建分布式系统,

我有两个问题:

            1.  性能怎么样,还需要后面测试一下

             2. client 调用 send.Send 这个方法执行是在server端,还是client端,我还不确定,(我猜测是server端)。

2.  应该是server端执行,否则异步就不需要了,从设计上看也应该是这样。

猜你喜欢

转载自blog.csdn.net/weixin_39594447/article/details/87342960