黑马头条项目 8.6 编写客户端

编程入门 行业动态 更新时间:2024-10-28 03:26:08

黑马<a href=https://www.elefans.com/category/jswz/34/1765373.html style=头条项目 8.6 编写客户端"/>

黑马头条项目 8.6 编写客户端

在toutiao-backend/common/rpc目录下新建client.py

import grpc
import reco_pb2
import reco_pb2_grpc
import timedef feed_articles(stub):# 构建rpc调用的调用参数user_request = reco_pb2.UserRequest()user_request.user_id = '1'user_request.channel_id = 1user_request.article_num = 10user_request.time_stamp = round(time.time()*1000)# 通过stub进行方法调用,并接收调用返回值ret = stub.user_recommend(user_request)print('ret={}'.format(ret))def run():"""构建连接rpc服务器的对象rpc客户端调用的方法"""# 使用with语句连接rpc服务器with grpc.insecure_channel('127.0.0.1:8888') as channel:# 创建调用rpc远端服务的辅助对象stubstub = reco_pb2_grpc.UserRecommendStub(channel)# 可以通过stub进行rpc调用# ret=stub.user_recommend()# 通过stub进行rpc调用feed_articles(stub)if __name__ == '__main__':run()

更多推荐

黑马头条项目 8.6 编写客户端

本文发布于:2024-02-16 19:07:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1691142.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:头条   黑马   客户端   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!