Skip to main content

RabbitMQ/AMQP-based RPC Client/Server Library

Project description

Author:

Nick Whalen <nickw@mindstorm-networks.net>

RabbitRPC is an RPC over AMQP framework. It allows the user to worry less about how he’s doing remote method calls and more about her/his actual code. It was written to scratch an itch that developed during the development of a much larger software project which needed a highly scalable internal API.

The framework is currently a work in progress. The basic client and server have been written/tested, but lack anything that make the framework ‘feel’ more like the method calls we’re used to. The next goal is to provide an additional layer on top of the existing client/server that will actually provide a dynamic interface which would allow you to do something like this on the client side:

import rpcclient

connection_settings = {
    'host': 'localhost',
    'port': 5672,
    'virtual_host': '/',
    'username': 'bob',
    'password': 'secret',
}

foo_class = rpcclient.RPCClient('remote_api_module_name', connection_settings=connection_settings)
return_value = foo_class.remote_api_method()

This will happen via server-side method registration. The RPC server will keep track of all public methods and, at the request of the RPC client, provide a list of these methods and their parameters. The RPC client will them use this list to dynamically build a stubbed out class. The stubs will call a translation method which will translate and pickle the method call and send it to the RPC request queue. A RPC worker can then take the API request package, process it, and return the results via the RPC server library.

Future plans also include the ability for the RPC workers to be versioned. This means you can spin up separate worker hives for varying implementations of your API.

Example

RPC Server:

from rabbitrpc import rpcserver

connection_settings = {
    'host': 'localhost',
    'port': 5672,
    'virtual_host': '/',
    'username': 'bob',
    'password': 'secret',
}

def rpc_callback(method_info):
    # Based on the data in method_info, select which method to call
    # Call it
    # Return the results

self.rpc_server = rpcserver.RPCServer(rpc_callback, 'RPCRequestQueue', connection_settings=connection_settings)

try:
    self.rpc_server.run()
finally:
    self.rpc_server.stop()

RPC Client:

from rabbitrpc import rpcclient

connection_settings = {
    'host': 'localhost',
    'port': 5672,
    'virtual_host': '/',
    'username': 'bob',
    'password': 'secret',
}

rpc_client = rpcclient.RPCClient('RPCRequestQueue', reply_timeout=3000, connection_settings=connection_settings)

request = # API call definition, any pickleable structure
reply = rpc_client.send(request)

print 'API REPLY: %s' % reply

Dependencies

Tests Only:

License

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rabbitrpc-0.5.1.tar.gz (5.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page