zeromicro / go-zero

A cloud-native Go microservices framework with cli tool for productivity.
https://go-zero.dev
MIT License
29.41k stars 3.97k forks source link

How can I use the API gateway of go zero as the client to call the RPC service of Python through grpc/我应该如何使用go-zero的api gateway作为客户端通过grpc调用python的rpc服务呢 #2193

Closed Dong148 closed 8 months ago

Dong148 commented 2 years ago

I started a python service generated by "grpc_tools", and then I tried to use API gateway to call it in the same way as the RPC service of gozero. This is an error message: (我启动了一个由“grpc_tools”生成的python服务,然后我试图利用api gateway以调用gozero的rpc服务相同的方式去调用它,这是报错信息:) {"@timestamp":"2022-07-26T12:24:36.333+08:00","caller":"internal/discovbuilder.go:34","content":"bad resolver state","level":"error"} 2022/07/26 12:24:39 rpc dial: discov://127.0.0.1:2379/replacer.rpc, error: context deadline exceeded, make sure rpc service "replacer.rpc" is already started

my api.yaml: `Name:test-api Host: 0.0.0.0 Port: 8888 Replace: Etcd: Hosts:

Although I execute the etcdctl command: (尽管我执行etcdctl命令:) etcdctl get replacer --prefix

output: (它会输出:) replacer.rpc ["127.0.0.1:8808"]

Code of my Python grpc service: (我的python gprc服务代码:) class Replacer(ReplacerServicer): def replace(self, context, request): return ReplaceResp(data=request.data)

def serve(service_ip="127.0.0.1", service_port=8808, etcd_ip="127.0.0.1", etcd_port=2379, etcd_prefix="replacer"): print(f"starting replacer service at: {service_ip}:{service_port}") server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) add_ReplacerServicer_to_server(Replacer, server) server.add_insecure_port(f'{service_ip}:{service_port}') handler_serv = EtcdHandleServ(service_ip=service_ip, service_port=service_port, etcd_ip=etcd_ip, etcd_port=etcd_port, etcd_prefix=etcd_prefix) handler_serv.register_service() server.start() print( f"replacer service started, responding at {service_ip}:{service_port}") server.wait_for_termination()

Is there a problem with my configuration? (我的配置有问题吗?)

Is it possible for me to call other services outside gozero through zrpc or any simple way in gozero? Or should I write additional grpc code? (请问我有可能在gozero中通过zrpc或任何简单的方式来调用gozero之外的其它服务吗?还是我应该编写额外的grpc代码?)

kevwan commented 2 years ago

You can call python grpc services like calling grpc services in Go.

Dong148 commented 2 years ago

You can call python grpc services like calling grpc services in Go. Thanks for your help, i previously assumed that zrpc is based on grpc and can work in the same way, and I don't need to care about this part of the work.

I have implemented my API gateway with fastapi for the time being, but I still hope to use gozero to implement most services in the future.

Our algorithm team uses Python to write services in the field of deep learning, but as a developer of application services,i hate the performance of Python and want to try the go language. At present, I think gozero is very convenient for novices like me. I want to know how we can complete the whole system more effectively.

With little time to read the source code, can I learn more about the structure and implementation details of gozero in other ways?

Thank you again.

kevwan commented 2 years ago

Just follow the QuickStart tutorials. And remember to join the community to discuss.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 8 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.