Skip to main content

RabbitMQ RPC server and client by BitNinja.io

Project description

BitNinjaIO NinjaRPC

RabbitMQ rpc server and client by BitNinja.io based on PHP implementation

Usage

The package contains a client, and a server as well, which can communicate with each other.

Server

# import the package
from ninjarpc import Server
from ninjarpc.Encoders import JsonEncoder
from ninjarpc.Routers import SimpleRouter
from ninjarpc.QueueManagers import RabbitMQ

def endpoint_handler(params):
    print(f'endpoint was called with {params} parameters.')

if __name__ == '__main__':
    queue_manager = RabbitMQ(host='hostname',
                             port='port',
                             username='username',
                             password='password')
    encoder = JsonEncoder()
    endpoints = {"endpoint": endpoint_handler}
    router = SimpleRouter(endpoints)

    server = Server('TEST_SERVICE', queue_manager, encoder, router)

    while True:
        server.listen()

Client

# import the package
from ninjarpc import Client
from ninjarpc.Encoders import JsonEncoder
from ninjarpc.Exceptions import CallTimeoutException
from ninjarpc.QueueManagers import RabbitMQ

if __name__ == '__main__':
    queue_manager = RabbitMQ(host='hostname',
                             port='port',
                             username='username',
                             password='password')
    encoder = JsonEncoder()
    client = Client(queue_manager, encoder)
    
    call = client.async_call(service_name='TEST_SERVICE',
                             method_name='endpoint',
                             parameters=())
    try: 
        result = call.wait()
    except CallTimeoutException as e:
        print('Call timeouted')

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

bitninja-ninjarpc-1.0.0.tar.gz (5.8 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