added ports to script arguments
This commit is contained in:
parent
62153ef88e
commit
8375b4b1e2
3 changed files with 28 additions and 9 deletions
|
@ -1,6 +1,5 @@
|
|||
FROM grpc/python:1.0
|
||||
|
||||
|
||||
# show python logs as they occur
|
||||
ENV PYTHONUNBUFFERED=0
|
||||
|
||||
|
@ -8,4 +7,7 @@ ENV PYTHONUNBUFFERED=0
|
|||
ADD ./*.py /home/
|
||||
WORKDIR /home
|
||||
|
||||
ENTRYPOINT python /home/recommendation_server.py
|
||||
# set listen port
|
||||
ENV PORT=8080
|
||||
|
||||
ENTRYPOINT python /home/recommendation_server.py $PORT
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
import grpc
|
||||
import demo_pb2
|
||||
import demo_pb2_grpc
|
||||
import sys
|
||||
|
||||
channel = grpc.insecure_channel('localhost:8081')
|
||||
stub = demo_pb2_grpc.RecommendationServiceStub(channel)
|
||||
if __name__ == "__main__":
|
||||
# get port
|
||||
if len(sys.argv) > 1:
|
||||
port = sys.argv[1]
|
||||
else:
|
||||
port = "8080"
|
||||
|
||||
request = demo_pb2.ListRecommendationsRequest(user_id="test", product_ids=["test"])
|
||||
# set up server stub
|
||||
channel = grpc.insecure_channel('localhost:'+port)
|
||||
stub = demo_pb2_grpc.RecommendationServiceStub(channel)
|
||||
|
||||
response = stub.ListRecommendations(request)
|
||||
# form request
|
||||
request = demo_pb2.ListRecommendationsRequest(user_id="test", product_ids=["test"])
|
||||
|
||||
print(response)
|
||||
# make call to server
|
||||
response = stub.ListRecommendations(request)
|
||||
print(response)
|
||||
|
|
|
@ -3,6 +3,7 @@ import demo_pb2
|
|||
import demo_pb2_grpc
|
||||
from concurrent import futures
|
||||
import time
|
||||
import sys
|
||||
|
||||
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
||||
def ListRecommendations(self, request, context):
|
||||
|
@ -22,6 +23,12 @@ class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
|||
return response
|
||||
|
||||
if __name__ == "__main__":
|
||||
# get port
|
||||
if len(sys.argv) > 1:
|
||||
port = sys.argv[1]
|
||||
else:
|
||||
port = "8080"
|
||||
|
||||
# create gRPC server
|
||||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
||||
|
||||
|
@ -29,8 +36,8 @@ if __name__ == "__main__":
|
|||
demo_pb2_grpc.add_RecommendationServiceServicer_to_server(RecommendationService(), server)
|
||||
|
||||
# start server
|
||||
print("Listening on port 8081")
|
||||
server.add_insecure_port('[::]:8081')
|
||||
print("Listening on port " + port)
|
||||
server.add_insecure_port('[::]:'+port)
|
||||
server.start()
|
||||
|
||||
# keep alive
|
||||
|
|
Loading…
Reference in a new issue