def test_should_roundtrip_headers(inbound, outbound): rpc = RPC( service='test-service', inbounds=[inbound], outbounds={ 'test-service': outbound, }, ) def hi(request): return Response( body=request.body, headers=request.headers, ) rpc.register(Procedure('hi', hi)) rpc.start() headers = { 'hello': 'world', 'mynameis': 'bob', } req = Request( encoding='raw', procedure='hi', headers=headers, ttl=10000, ) resp = yield rpc.channel('test-service').call(req) assert headers == resp.headers
def test_should_call_procedure(inbound, outbound): rpc = RPC( service='test-service', inbounds=[inbound], outbounds={ 'test-service': outbound, }, ) def hi(request): assert isinstance(request, Request) assert request.encoding == 'raw' assert request.procedure == 'hi' assert request.body == 'hello' return Response(body="%s" % request.body) rpc.register(Procedure('hi', hi)) rpc.start() req = Request( encoding='raw', procedure='hi', body='hello', ttl=10000, ) resp = hi(req) assert isinstance(resp, Response) assert resp.body == 'hello' resp = yield rpc.channel('test-service').call(req) assert isinstance(resp, Response) assert resp.body == 'hello'
def rpc(io_loop, inbound, outbound): rpc = RPC( service='test-service', inbounds=[inbound], outbounds={ 'test-service': outbound, }, ) try: rpc.start() yield rpc finally: rpc.stop()
def start(): rpc = RPC( service='yarpc-test', inbounds=[ http.HTTPInbound(transport.HTTP_PORT), tchannel.TChannelInbound( TChannel( name='yarpc-test', # TODO shouldnt rpc set this somehow? hostport="0.0.0.0:%s" % transport.TCHANNEL_PORT ), ) ], ) rpc.register(procedure.raw) rpc.register(procedure.json) rpc.register(procedure.thrift) rpc.register(procedure.phone) rpc.register(procedure.unexpected) rpc.register(procedure.bad) rpc.start()
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from __future__ import ( absolute_import, division, print_function, unicode_literals ) from yarpc import RPC, Response from yarpc_sync.inbounds import HTTPInbound rpc = RPC( service='test-service', inbounds=[HTTPInbound(port=8888)], ) def test(request): # resp = rpc.json('billy', {'hello':'world'}) return Response(body="test: %s" % request.body) def test2(request): return Response(body="test2: %s" % request.body) rpc.raw.register('test', test) rpc.raw.register('test2', test2) if __name__ == '__main__': rpc.start()