added client
This commit is contained in:
parent
9c6f36c605
commit
62153ef88e
4 changed files with 27 additions and 3 deletions
12
src/recommendationservice/client.py
Normal file
12
src/recommendationservice/client.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import grpc
|
||||||
|
import demo_pb2
|
||||||
|
import demo_pb2_grpc
|
||||||
|
|
||||||
|
channel = grpc.insecure_channel('localhost:8081')
|
||||||
|
stub = demo_pb2_grpc.RecommendationServiceStub(channel)
|
||||||
|
|
||||||
|
request = demo_pb2.ListRecommendationsRequest(user_id="test", product_ids=["test"])
|
||||||
|
|
||||||
|
response = stub.ListRecommendations(request)
|
||||||
|
|
||||||
|
print(response)
|
BIN
src/recommendationservice/demo_pb2.pyc
Normal file
BIN
src/recommendationservice/demo_pb2.pyc
Normal file
Binary file not shown.
BIN
src/recommendationservice/demo_pb2_grpc.pyc
Normal file
BIN
src/recommendationservice/demo_pb2_grpc.pyc
Normal file
Binary file not shown.
|
@ -6,7 +6,19 @@ import time
|
||||||
|
|
||||||
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
||||||
def ListRecommendations(self, request, context):
|
def ListRecommendations(self, request, context):
|
||||||
|
print("handling request")
|
||||||
response = demo_pb2.ListRecommendationsResponse()
|
response = demo_pb2.ListRecommendationsResponse()
|
||||||
|
prod_list = []
|
||||||
|
for i in range(3):
|
||||||
|
this_price = demo_pb2.MoneyAmount(decimal=i,
|
||||||
|
fractional=i)
|
||||||
|
this_prod = demo_pb2.Product(id=i,
|
||||||
|
name="test-"+str(i),
|
||||||
|
description="test product",
|
||||||
|
picture="test image",
|
||||||
|
price_usd=this_price)
|
||||||
|
prod_list.append(this_prod)
|
||||||
|
response.products.extend(prod_list)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -17,13 +29,13 @@ 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 8080")
|
print("Listening on port 8081")
|
||||||
server.add_insecure_port('[::]:8080')
|
server.add_insecure_port('[::]:8081')
|
||||||
server.start()
|
server.start()
|
||||||
|
|
||||||
# keep alive
|
# keep alive
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
time.sleep(86400)
|
time.sleep(10000)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
server.stop(0)
|
server.stop(0)
|
||||||
|
|
Loading…
Reference in a new issue