【问题标题】:How to deploy gRPC server/client to heroku?如何将 gRPC 服务器/客户端部署到 heroku?
【发布时间】:2017-12-06 19:53:28
【问题描述】:

我将我的 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)

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

【问题讨论】:

  • 您有多确定 gRPC 与问题有关?您是否在 Heroku 环境中运行过普通的 HTTP 服务器并能够连接到它?
  • @NathanielManistaAtGoogle 可以肯定的是,我能够成功地与普通服务器通信。 gRPC 应用程序在本地也能完美运行。不是 gRPC 有问题,我只是不确定如何部署它并连接到服务器。

标签: python heroku deployment grpc


【解决方案1】:

Heroku does not support HTTP 2。另一方面,GRPC 使用基于 http/2 的传输。我认为这就是为什么您可以在本地连接它而不是从 Heroku 连接它的原因。

【讨论】:

    猜你喜欢
    • 2022-10-26
    • 1970-01-01
    • 2019-02-06
    • 1970-01-01
    • 2020-09-09
    • 2020-08-22
    • 2018-04-12
    • 1970-01-01
    • 2016-01-27
    相关资源
    最近更新 更多