0
当我尝试在Amazon EC2实例上构建gRPC服务器/客户端时遇到问题。在Amazon EC2上构建gRPC服务器
我有一个实例A(与私人IP:例如1.2.3.4)。服务器的代码是一样
from concurrent import futures
import time
import math
import grpc
import helloworld_pb2
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
class Greeter(helloworld_pb2.GreeterServicer):
def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
helloworld_pb2.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('1.2.3.4:50051')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
serve()
在另一方面,该实例B具有私有IP 2.3.4.5,我想它
from __future__ import print_function
import grpc
import helloworld_pb2
def run():
channel = grpc.insecure_channel('1.2.3.4:50051')
stub = helloworld_pb2.GreeterStub(channel)
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
print("Greeter client received: " + response.message)
if __name__ == '__main__':
run()
客户端和服务器端的代码运行运行客户端脚本以及在本地机器上。然而,当我尝试在EC2集群上运行他们的客户端无法找到服务器
Traceback (most recent call last):
File "helloworld_client.py", line 47, in <module>
run()
File "helloworld_client.py", line 42, in run
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
File "/usr/local/lib/python3.4/dist-packages/grpc/_channel.py", line 481, in __call__
return _end_unary_response_blocking(state, False, deadline)
File "/usr/local/lib/python3.4/dist-packages/grpc/_channel.py", line 432, in _end_unary_response_blocking
raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE,)>
我应该怎么做才能拿到剧本运行?
感谢。