Skip to main content

Django wrapper for nameko microservice framework.

Project description

django-nameko

Travis-CI Coverage Status

Branch Build status
master Build Status
develop Build Status

Django wrapper for Nameko microservice framework.

support

tested with

  • python 2.7, 3.5, 3.6, 3.7
  • django 1.11, 2.0, 2.1, 2.2
  • nameko 2.11, 2.12

How to use

from django_nameko import get_pool           

# Within some view or model:
with get_pool().next() as rpc:
    rpc.mailer.send_mail(foo='bar')

Installation

pip install django-nameko

Configuration

# Config to be passed to ClusterRpcProxy 
NAMEKO_CONFIG = { 
    'AMQP_URI': 'amqp://127.0.0.1:5672/'
}  

# Number of proxies to create 
# Each proxy is a single threaded standalone ClusterRpcProxy
NAMEKO_POOL_SIZE = 4
# Set timeout for RPC
NAMEKO_TIMEOUT = 15  # timeout 15 seconds
# Add this dictionary to context_data of every RPC
NAMEKO_CONTEXT_DATA = {
    'hostname': "my.example.com"
}

# Create multiple ClusterRpcProxy pool each one assoiate with a name
# Every pool with pool name different than 'default' will use 'default' pool config as default configuration
NAMEKO_CONFIG={
    'default': {
        'AMQP_URI': 'amqp://',
        'POOL_SIZE': 4,
        'POOL_CONTEXT_DATA': {"common": "multi"},
        'POOL_TIMEOUT': None
    },
    'pool1': {
        'AMQP_URI': 'amqp://pool2',
        'POOL_CONTEXT_DATA': {"name": "pool1", "data": 123},
    },
    'pool2': {
        'AMQP_URI': 'amqp://pool3',
        'POOL_CONTEXT_DATA': {"name": "pool2", "data": 321},
        'POOL_TIMEOUT': 60
    },
    'pool3': {
        'POOL_SIZE': 8,
        'POOL_TIMEOUT': 60
    }
}
# Use multi pool by putting pool name in get_pool(..)
from django_nameko import get_pool

with get_pool('pool1').next() as rpc:
    rpc.mailer.send_mail(foo='bar')
    
# call get_pool() without argument will return the 'default' pool
# but you can override the rpc context data before call, example below.
# it will auto revert back to POOL_CONTEXT_DATA when exit the with block
with get_pool().next() as rpc:
    rpc._worker_ctx.data['SMTP_SECRET'] = 'SECRETXXX'
    rpc.mailer.send_mail(foo='bar')

# try to call rpc outside of with statement block will raise an AttributeError exception 
rpc.mailer.send_mail(bar='foo')
#   File "/usr/local/lib/python2.7/site-packages/django_nameko/rpc.py", line 69, in __getattr__
#     raise AttributeError(item)
# AttributeError: mailer

contribute

to run the tests:

  1. run a local rabbitmq
  2. execute tox
docker run --rm -p 15672:15672 -p 5672:5672 -p 5671:5671 --name nameko-rabbitmq nameko/nameko-rabbitmq:3.6.6
# open another shell then run
python setup.py test
# to run full test with coverage use
tox 

Credits

Thanks to guys who made an awesome Nameko framework.

Maintainers:

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

django-nameko-0.6.1.tar.gz (20.7 kB view details)

Uploaded Source

File details

Details for the file django-nameko-0.6.1.tar.gz.

File metadata

  • Download URL: django-nameko-0.6.1.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.15

File hashes

Hashes for django-nameko-0.6.1.tar.gz
Algorithm Hash digest
SHA256 09fd6efe39374a8dde75133b8a936f73b4c3fdf372777e224d8102b8c581dba9
MD5 e9b8d374325e9f589623d1db9f1b8d1e
BLAKE2b-256 656a35a59033282581fd27bc7deb5514533545e841bbaa3ed3563e1239655828

See more details on using hashes here.

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