regenerated protos

This commit is contained in:
Dan Sanche 2018-06-20 23:40:47 -07:00
parent 933a05205f
commit 61291a5105
3 changed files with 67 additions and 104 deletions

File diff suppressed because one or more lines are too long

View File

@ -283,8 +283,8 @@ class CurrencyServiceStub(object):
)
self.Convert = channel.unary_unary(
'/hipstershop.CurrencyService/Convert',
request_serializer=demo__pb2.ConversionRequest.SerializeToString,
response_deserializer=demo__pb2.ConversionResponse.FromString,
request_serializer=demo__pb2.CurrencyConversionRequest.SerializeToString,
response_deserializer=demo__pb2.Money.FromString,
)
@ -317,8 +317,8 @@ def add_CurrencyServiceServicer_to_server(servicer, server):
),
'Convert': grpc.unary_unary_rpc_method_handler(
servicer.Convert,
request_deserializer=demo__pb2.ConversionRequest.FromString,
response_serializer=demo__pb2.ConversionResponse.SerializeToString,
request_deserializer=demo__pb2.CurrencyConversionRequest.FromString,
response_serializer=demo__pb2.Money.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(

View File

@ -9,16 +9,19 @@ import os
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
def ListRecommendations(self, request, context):
max_responses = 5
print("handling request")
# get list of products
# fetch list of products from product catalog stub
cat_response = stub.ListProducts(demo_pb2.Empty())
num_prodcuts = len(cat_response.products)
num_return = min(max_responses, num_prodcuts)
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)
# sample list of indicies to return
indices = random.sample(range(num_prodcuts), num_return)
# fetch product ids from indices
prod_list = [cat_response.products[i].id for i in indices]
print("handling request: {}".format(prod_list))
# build and return response
response = demo_pb2.ListRecommendationsResponse()
response.product_ids.extend(prod_list)
return response