added product catalog address env var
This commit is contained in:
parent
1fc51262ff
commit
c753f9a6ff
2 changed files with 13 additions and 9 deletions
|
@ -8,6 +8,9 @@ ADD ./*.py /home/
|
||||||
WORKDIR /home
|
WORKDIR /home
|
||||||
|
|
||||||
# set listen port
|
# set listen port
|
||||||
ENV PORT=8080
|
ENV PORT="8080"
|
||||||
|
|
||||||
ENTRYPOINT python /home/recommendation_server.py $PORT
|
#set product catalog address
|
||||||
|
ENV PRODUCT_CATALOG_SERVICE_ADDR="localhost:8081"
|
||||||
|
|
||||||
|
ENTRYPOINT python /home/recommendation_server.py
|
||||||
|
|
|
@ -3,8 +3,8 @@ 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
|
|
||||||
import random
|
import random
|
||||||
|
import os
|
||||||
|
|
||||||
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
||||||
def ListRecommendations(self, request, context):
|
def ListRecommendations(self, request, context):
|
||||||
|
@ -17,11 +17,13 @@ class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# get port
|
# get port from $PORT envar
|
||||||
if len(sys.argv) > 1:
|
port = os.environ.get('PORT', "8080")
|
||||||
port = sys.argv[1]
|
# get product catalog service address from $PRODUCT_CATALOG_SERVICE_ADDR envar
|
||||||
else:
|
catalog_addr = os.environ.get('PRODUCT_CATALOG_SERVICE_ADDR', "localhost:8081")
|
||||||
port = "8080"
|
|
||||||
|
print("product catalog address: " + catalog_addr)
|
||||||
|
print("listening on port: " + port)
|
||||||
|
|
||||||
# create gRPC server
|
# create gRPC server
|
||||||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
||||||
|
@ -30,7 +32,6 @@ 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 " + port)
|
|
||||||
server.add_insecure_port('[::]:'+port)
|
server.add_insecure_port('[::]:'+port)
|
||||||
server.start()
|
server.start()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue