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,)>
我應該怎麼做才能拿到劇本運行?
感謝。