smallnest / rpcx

Best microservices framework in Go, like alibaba Dubbo, but with more features, Scale easily. Try it. Test it. If you feel it's better, use it! 𝐉𝐚𝐯𝐚有𝐝𝐮𝐛𝐛𝐨, 𝐆𝐨𝐥𝐚𝐧𝐠有𝐫𝐩𝐜𝐱! build for cloud!
https://rpcx.io
Other
8.11k stars 1.17k forks source link

客户端如何等待进行中的请求都执行完成再安全关闭? #781

Closed zhmm closed 1 year ago

zhmm commented 1 year ago

场景: 程序a中消费mq中数据,再rpc远程调用服务b, 程序a在重启时候需要等xclient.call的所有都请求都执行完成再关闭,现在a程序a中已经监听信号,收到停止信号执行一系列操作,但是如何确保xclient.call正在进行中的这些请求都处理完成再停止服务?

smallnest commented 1 year ago

你可以使用一个计数器,调用前+1, 调用完减1. a收到停止信号检查计数器,等计数器变为0后可以安全退出