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
|
FROM grpc/python:1.0
|
||||||
|
|
||||||
|
|
||||||
# show python logs as they occur
|
# show python logs as they occur
|
||||||
ENV PYTHONUNBUFFERED=0
|
ENV PYTHONUNBUFFERED=0
|
||||||
|
|
||||||
|
@ -8,4 +7,7 @@ ENV PYTHONUNBUFFERED=0
|
||||||
ADD ./*.py /home/
|
ADD ./*.py /home/
|
||||||
WORKDIR /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 grpc
|
||||||
import demo_pb2
|
import demo_pb2
|
||||||
import demo_pb2_grpc
|
import demo_pb2_grpc
|
||||||
|
import sys
|
||||||
|
|
||||||
channel = grpc.insecure_channel('localhost:8081')
|
if __name__ == "__main__":
|
||||||
stub = demo_pb2_grpc.RecommendationServiceStub(channel)
|
# 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
|
import demo_pb2_grpc
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
||||||
def ListRecommendations(self, request, context):
|
def ListRecommendations(self, request, context):
|
||||||
|
@ -22,6 +23,12 @@ class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
# get port
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
port = sys.argv[1]
|
||||||
|
else:
|
||||||
|
port = "8080"
|
||||||
|
|
||||||
# create gRPC server
|
# create gRPC server
|
||||||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
||||||
|
|
||||||
|
@ -29,8 +36,8 @@ if __name__ == "__main__":
|
||||||
demo_pb2_grpc.add_RecommendationServiceServicer_to_server(RecommendationService(), server)
|
demo_pb2_grpc.add_RecommendationServiceServicer_to_server(RecommendationService(), server)
|
||||||
|
|
||||||
# start server
|
# start server
|
||||||
print("Listening on port 8081")
|
print("Listening on port " + port)
|
||||||
server.add_insecure_port('[::]:8081')
|
server.add_insecure_port('[::]:'+port)
|
||||||
server.start()
|
server.start()
|
||||||
|
|
||||||
# keep alive
|
# keep alive
|
||||||
|
|
Loading…
Reference in a new issue