# Config to be passed to ClusterRpcProxyNAMEKO_CONFIG={'AMQP_URI':'amqp://127.0.0.1:5672/'}# Number of proxies to create# Each proxy is a single threaded standalone ClusterRpcProxyNAMEKO_POOL_SIZE=4# Set timeout for RPCNAMEKO_TIMEOUT=15# timeout 15 seconds# Add this dictionary to context_data of every RPCNAMEKO_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 configurationNAMEKO_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(..)fromdjango_namekoimportget_poolwithget_pool('pool1').next()asrpc: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 blockwithget_pool().next()asrpc: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 exceptionrpc.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
python nameko_Python django-nameko包_程序模块 - PyPI - Python中文网
最新推荐文章于 2022-02-18 16:37:24 发布