Ejemplo n.º 1
0
# import the generated classes
import proto.calculator_pb2 as calculator_pb2
import proto.calculator_pb2_grpc as calculator_pb2_grpc

# ******* Testing our square calculator function **********

# Open a gRPC channel
channel = grpc.insecure_channel('localhost:50051')

# Create a stub (client)
stub = calculator_pb2_grpc.CalculatorStub(channel)

# Create a valid request message
# (basically create an object of type 'calculator_pb2.Number'.)
a_number = calculator_pb2.Number(value=16)

# Call the Square method and collect response.
response = stub.Square(a_number)

# Let's see the results.
print(response.value)

# ******* Testing our multiplier function **********
num_list = calculator_pb2.NumList()
num_list.name = 'MyFirstList'
n1 = num_list.nums.add()
n2 = num_list.nums.add()
n3 = num_list.nums.add()
n1.value = 10
n2.value = 20
Ejemplo n.º 2
0
 def yieldMsg():
     for x in range(200, 300):
         yield calculator_pb2.Number(value=x)
Ejemplo n.º 3
0
def squareRoot(stub):
    response = stub.SquareRoot(calculator_pb2.Number(value=16))
    print(response.value)
Ejemplo n.º 4
0
 def SquareRoot(self, request, context):
     response = calculator_pb2.Number()
     response.value = (request.value) * (request.value)
     return response
Ejemplo n.º 5
0
 def yieldEvents():
     for x in range(100, 111):
         yield calculator_pb2.Number(value=x)
Ejemplo n.º 6
0
 def Chat(self, request_iterator, context):
     for req in request_iterator:
         yield calculator_pb2.Number(value=(req.value + 11))
Ejemplo n.º 7
0
 def SendEvents(self, request_iterator, context):
     count = 0
     for req in request_iterator:
         print("Receive: %s, context: %s" % (req.value, context))
         count += 1
     return calculator_pb2.Number(value=count)
Ejemplo n.º 8
0
 def ReceiveEvents(self, request, context):
     for x in range(10):
         yield calculator_pb2.Number(value=x)
         time.sleep(0.3)
Ejemplo n.º 9
0
 def say_hello(self):
     req_data = calculator_pb2.Number(value=16)
     self.locust_request_handler("say_hello", req_data)
Ejemplo n.º 10
0
 def Multiplier(self, request, context):
     response = calculator_pb2.Number()
     response.value = calculator.multiplier(request.nums, request.name)
     return response