chained RPC calls

#1

I have an application that has 3 containers, let’s call them A, B, and C. Containers B and C both have successfully registered remote procedures. I can successfully call both RPC’s from A, so I know that they function. What I would like to do is have A call an RPC that is resident in B. However in order for B to return a value to A, it first needs to call an RPC in C. The result of the RPC call to C is applied within the B Remote Procedure before it returns a value to A.

I have not been able to successfully chain RPC’s in this fashion. I am obviously missing a very basic point and would like to understand what I am missing.

Thanks in advance.

Initially I tried doing the following:

# this is container B and mul2 is called from container A
def mul2(x, y):
 print("add2() called with {} and {}".format(x, y))
 z = yield self.call('com.example.add2', 55, 3)
 return x + y + z

reg = yield self.register(mul2, 'com.example.mul2')
print("procedure mul2() registered: {}".format(reg))

The return statement shows a syntax error: Python versions <3.3 do not allow ‘return’ with argument inside generator.

So I tried the following:

def mul2(x, y):
 print("mul2() called with {} and {}".format(x, y))
 r = call_hello(5, 6)
 return x * y * r

reg = yield self.register(mul2, 'com.example.mul2')
print("procedure mul2() registered: {}".format(reg))

# add 2 is an RPC in container C
def call_hello(x, y):
 print("entered call_hello")
 res = yield self.call('com.example.add2',x, y)

Placing a breakpoint at r = call_hello(5,6), and executing that statement, r is identified as a generator object.

So I thought I would then modify the code this way:

def mul2(x, y):
 print("mul2() called with {} and {}".format(x, y))
 r = call_hello(5, 6)

 for value in r:
  print("Value = ", value)

 return x * y * r

reg = yield self.register(mul2, 'com.example.mul2')
print("procedure mul2() registered: {}".format(reg))

def call_hello(x, y):
 print("entered call_hello")
 res = yield self.call('com.example.add2',x, y)

Putting a breakpoint on print("Value = ",value) value is identified as deferred, but this time a print statement at the entry to add2 is printed but nothing is returned.

Here is the code for add2:

def add2(x, y):
 print("add2() called with {} and {}".format(x, y))
 return x + y

reg = yield self.register(add2, 'com.example.add2')
print("procedure add2() registered: {}".format(reg))
0 Likes