如何将gRPC服务器/客户端部署到heroku?

前端之家收集整理的这篇文章主要介绍了如何将gRPC服务器/客户端部署到heroku?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我将我的python gRPC服务器部署到Heroku,并想知道如何使用本地Python客户端测试它.

server.py

def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    icp_pb2_grpc.add_MyServicer_to_server(MyServicer(),server)

    server_port = os.environ.get('PORT',50051) 
    server.add_insecure_port('[::]:'+ str(server_port))
    server.start()
    print("==== SERVER RUNNING =====")
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)

if __name__ == '__main__':
    serve()

client.py

def run():
    # Is the channel url correct?
    channel = grpc.insecure_channel('https://www.HEROKUURL.com:50051')
    stub = my_grpc.MyStub(channel)
    file = _get_file_content()
    response = stub.Predict(icp_pb2.MyRequest(file_content=file))
    print("received: " + response.results)

我正在使用计算机上的客户端,但是没有收到服务器的任何响应.如果在本地启动,我能够成功与服务器通信.我究竟做错了什么?

@H_404_21@最佳答案
Heroku does not support HTTP 2.另一方面,GRPC使用基于http / 2的传输.我认为这就是为什么你可以在本地连接,但不能从Heroku连接.
原文链接:https://www.f2er.com/python/438818.html

猜你在找的Python相关文章