pull ids from product catalog service
This commit is contained in:
parent
c753f9a6ff
commit
933a05205f
1 changed files with 14 additions and 3 deletions
|
@ -8,11 +8,18 @@ import os
|
||||||
|
|
||||||
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
||||||
def ListRecommendations(self, request, context):
|
def ListRecommendations(self, request, context):
|
||||||
|
max_responses = 5
|
||||||
print("handling request")
|
print("handling request")
|
||||||
|
|
||||||
|
# get list of products
|
||||||
|
cat_response = stub.ListProducts(demo_pb2.Empty())
|
||||||
|
num_prodcuts = len(cat_response.products)
|
||||||
|
|
||||||
|
indices = random.sample(range(num_prodcuts), min(max_responses, num_prodcuts))
|
||||||
|
prod_list = [str(cat_response.products[i].id) for i in indices]
|
||||||
|
print(indices, prod_list)
|
||||||
|
|
||||||
response = demo_pb2.ListRecommendationsResponse()
|
response = demo_pb2.ListRecommendationsResponse()
|
||||||
prod_list = []
|
|
||||||
for i in range(5):
|
|
||||||
prod_list.append(str(random.randint(1,100)))
|
|
||||||
response.product_ids.extend(prod_list)
|
response.product_ids.extend(prod_list)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -25,6 +32,10 @@ if __name__ == "__main__":
|
||||||
print("product catalog address: " + catalog_addr)
|
print("product catalog address: " + catalog_addr)
|
||||||
print("listening on port: " + port)
|
print("listening on port: " + port)
|
||||||
|
|
||||||
|
# stub for product catalog service
|
||||||
|
channel = grpc.insecure_channel(catalog_addr)
|
||||||
|
stub = demo_pb2_grpc.ProductCatalogServiceStub(channel)
|
||||||
|
|
||||||
# create gRPC server
|
# create gRPC server
|
||||||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue