How to use the nameko.standalone.rpc.ClusterRpcProxy function in nameko

To help you get started, we’ve selected a few nameko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nameko / nameko / test / cli / test_run.py View on Github external
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()
github etalab / croquemort / tests / example_csv.py View on Github external
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)))
github nameko / nameko / test / standalone / test_rpc_proxy.py View on Github external
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
github nameko / nameko / test / standalone / test_rpc_proxy.py View on Github external
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
github jessepollak / flask-nameko / flask_nameko / proxies.py View on Github external
def _get_nameko_connection(self):
        proxy = ClusterRpcProxy(
            self._config,
            timeout=self._config.get('RPC_TIMEOUT', None)
        )
        return proxy.start()
github nameko / nameko / nameko / standalone / rpc.py View on Github external
def __init__(self, *args, **kwargs):
        super(ClusterRpcProxy, self).__init__(*args, **kwargs)
        self._proxy = ClusterProxy(self._worker_ctx, self._reply_listener)
github PacktPublishing / Microservice-Patterns-and-Best-Practices / Chapter10 / NewsOrchestrator / views.py View on Github external
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)
        }
github PacktPublishing / Python-Programming-Blueprints / Chapter06 / temp_messenger / web_server.py View on Github external
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
github PacktPublishing / Microservice-Patterns-and-Best-Practices / Chapter10 / NewsOrchestrator / views.py View on Github external
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,
        }
github nameko / nameko / docs / examples / standalone_rpc.py View on Github external
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"