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.1.0.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file bitninja-ninjarpc-1.1.0.tar.gz.

File metadata

  • Download URL: bitninja-ninjarpc-1.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for bitninja-ninjarpc-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f27600282fec323fc24ec39ee9ecaba94d3d05850376b465af124ec61680a327
MD5 65065e4259a137cf8bddd6e7e308b7b4
BLAKE2b-256 3cd7e2c16b4644a7f913704e79da1e6348d53ae8397bec68ae8d148b7aa6e115

See more details on using hashes here.

Supported by

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