Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
amqp_uri=rabbit_config['AMQP_URI']
))
)
parser = setup_parser()
args = parser.parse_args([
'run',
'--config',
config_file.strpath,
'test.sample',
])
gt = eventlet.spawn(main, args)
eventlet.sleep(1)
with ClusterRpcProxy(rabbit_config) as proxy:
proxy.service.ping()
pid = os.getpid()
os.kill(pid, signal.SIGTERM)
gt.wait()
assert "test.sample - INFO - ping!" in capture_file.read()
from nameko.standalone.rpc import ClusterRpcProxy
from croquemort.tools import generate_hash_for
config = {
'AMQP_URI': 'amqp://guest:guest@localhost',
'REDIS_URI': 'redis://localhost:6379/0',
}
parser = argparse.ArgumentParser()
parser.add_argument('--csvfile', type=argparse.FileType('r'), required=True)
parser.add_argument('--group')
parser.add_argument('--frequency')
args = parser.parse_args()
with ClusterRpcProxy(config) as cluster_rpc:
for line in args.csvfile:
url = line.strip('\n')
cluster_rpc.http_server.fetch.async(url, args.group or None,
args.frequency or None)
if args.group:
print('Group hash: {hash}'.format(hash=generate_hash_for('group',
args.group)))
def test_cluster_proxy(container_factory, rabbit_manager, rabbit_config):
container = container_factory(FooService, rabbit_config)
container.start()
with ClusterRpcProxy(rabbit_config) as proxy:
assert proxy.foobar.spam(ham=1) == 1
def test_multi_cluster_proxy_dict_access(container_factory, rabbit_manager, rabbit_config):
container = container_factory(FooService, rabbit_config)
container.start()
with ClusterRpcProxy(rabbit_config, reply_listener_cls=MultiReplyListener) as proxy:
assert proxy['foobar'].spam(ham=3) == 3
def _get_nameko_connection(self):
proxy = ClusterRpcProxy(
self._config,
timeout=self._config.get('RPC_TIMEOUT', None)
)
return proxy.start()
def __init__(self, *args, **kwargs):
super(ClusterRpcProxy, self).__init__(*args, **kwargs)
self._proxy = ClusterProxy(self._worker_ctx, self._reply_listener)
def rpc_get_news(news_type, news_id):
with ClusterRpcProxy(BROKER_CONFIG) as rpc:
if news_type == 'famous':
news = rpc.query_famous.get_news(news_id)
elif news_type == 'sports':
news = rpc.query_sports.get_news(news_id)
elif news_type == 'politics':
news = rpc.query_politics.get_news(news_id)
else:
return erro_response('Invalid News type', 400)
return {
'status': 'success',
'news': json.loads(news)
}
def post(self):
if not user_authenticated():
return 'Please log in', 401
email = session['email']
data = request.get_json(force=True)
try:
message = data['message']
except KeyError:
return 'No message given', 400
with ClusterRpcProxy(config) as rpc:
rpc.message_service.save_message(email, message)
return '', 204
def rpc_command(news_type, data):
with ClusterRpcProxy(BROKER_CONFIG) as rpc:
if news_type == 'famous':
news = rpc.command_famous.add_news(data)
elif news_type == 'sports':
news = rpc.command_sports.add_news(data)
elif news_type == 'politics':
news = rpc.command_politics.add_news(data)
else:
return erro_response('Invalid News type', 400)
return {
'status': 'success',
'news': news,
}
from nameko.standalone.rpc import ClusterRpcProxy
config = {
'AMQP_URI': AMQP_URI # e.g. "pyamqp://guest:guest@localhost"
}
with ClusterRpcProxy(config) as cluster_rpc:
cluster_rpc.service_x.remote_method("hellø") # "hellø-x-y"