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( self.Convert = channel.unary_unary(
'/hipstershop.CurrencyService/Convert', '/hipstershop.CurrencyService/Convert',
request_serializer=demo__pb2.ConversionRequest.SerializeToString, request_serializer=demo__pb2.CurrencyConversionRequest.SerializeToString,
response_deserializer=demo__pb2.ConversionResponse.FromString, response_deserializer=demo__pb2.Money.FromString,
) )
@ -317,8 +317,8 @@ def add_CurrencyServiceServicer_to_server(servicer, server):
), ),
'Convert': grpc.unary_unary_rpc_method_handler( 'Convert': grpc.unary_unary_rpc_method_handler(
servicer.Convert, servicer.Convert,
request_deserializer=demo__pb2.ConversionRequest.FromString, request_deserializer=demo__pb2.CurrencyConversionRequest.FromString,
response_serializer=demo__pb2.ConversionResponse.SerializeToString, response_serializer=demo__pb2.Money.SerializeToString,
), ),
} }
generic_handler = grpc.method_handlers_generic_handler( generic_handler = grpc.method_handlers_generic_handler(

View file

@ -9,16 +9,19 @@ 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 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()) cat_response = stub.ListProducts(demo_pb2.Empty())
num_prodcuts = len(cat_response.products) num_prodcuts = len(cat_response.products)
num_return = min(max_responses, num_prodcuts)
indices = random.sample(range(num_prodcuts), min(max_responses, num_prodcuts)) # sample list of indicies to return
prod_list = [str(cat_response.products[i].id) for i in indices] indices = random.sample(range(num_prodcuts), num_return)
print(indices, prod_list) # 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 = demo_pb2.ListRecommendationsResponse()
response.product_ids.extend(prod_list) response.product_ids.extend(prod_list)
return response return response