Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError 'REDIS_URIS' #7

Open
staskuban opened this issue Jan 25, 2019 · 3 comments
Open

KeyError 'REDIS_URIS' #7

staskuban opened this issue Jan 25, 2019 · 3 comments

Comments

@staskuban
Copy link

staskuban commented Jan 25, 2019

With config for serviceRunner i got KeyError: 'REDIS_URIS'

Sample serviceRunner code:

from nameko.runners import ServiceRunner
import eventlet;
eventlet.monkey_patch()

from services.ServiceOne import ServiceOne
from services.ServiceTwo import ServiceTwo


config = {
    'REDIS_URIS': {'redis': 'redis://127.0.0.1:32768/10'},
    'AMQP_URI': 'pyamqp://guest:guest@localhost',
    'WEB_SERVER_ADDRESS': '0.0.0.0:8000',
    'rpc_exchange': 'nameko-rpc',
    'max_workers': 10,
    'parent_calls_tracked': 10
}

runner = ServiceRunner(config=config)
runner.add_service(ServiceOne)
runner.add_service(ServiceTwo)
runner.start()

Full error message:

Traceback (most recent call last):
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/bin/nameko", line 11, in <module>
    sys.exit(main())
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/nameko/cli/main.py", line 107, in main
    args.main(args)
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/nameko/cli/commands.py", line 110, in main
    main(args)
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/nameko/cli/run.py", line 184, in main
    run(services, config, backdoor_port=args.backdoor_port)
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/nameko/cli/run.py", line 131, in run
    service_runner.start()
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/nameko/runners.py", line 66, in start
    SpawningProxy(self.containers).start()
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/nameko/utils/__init__.py", line 186, in spawning_method
    return list(pool.imap(call, self._items))
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/eventlet/greenpool.py", line 244, in next
    val = self.waiters.get().wait()
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/eventlet/greenthread.py", line 180, in wait
    return self._exit_event.wait()
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/eventlet/event.py", line 132, in wait
    current.throw(*self._exc)
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/eventlet/greenthread.py", line 219, in main
    result = function(*args, **kwargs)
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/nameko/utils/__init__.py", line 181, in call
    return getattr(item, name)(*args, **kwargs)
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/nameko/containers.py", line 188, in start
    self.extensions.all.setup()
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/nameko/utils/__init__.py", line 186, in spawning_method
    return list(pool.imap(call, self._items))
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/eventlet/greenpool.py", line 244, in next
    val = self.waiters.get().wait()
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/eventlet/greenthread.py", line 180, in wait
    return self._exit_event.wait()
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/eventlet/event.py", line 125, in wait
    result = hub.switch()
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/eventlet/hubs/hub.py", line 297, in switch
    return self.greenlet.switch()
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/eventlet/greenthread.py", line 219, in main
    result = function(*args, **kwargs)
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/nameko/utils/__init__.py", line 181, in call
    return getattr(item, name)(*args, **kwargs)
  File "/Users/stasb/PycharmProject/testNAMEKO/venv/lib/python3.7/site-packages/nameko_redis.py", line 19, in setup
    redis_uris = self.container.config[REDIS_URIS_KEY]
KeyError: 'REDIS_URIS'

Can you help with my problem?

@etataurov
Copy link
Owner

etataurov commented Jan 26, 2019

Hello,

I cannot reproduce with this example

from nameko.runners import ServiceRunner
import eventlet;
eventlet.monkey_patch()

from nameko.rpc import rpc
from nameko_redis import Redis


class MyService(object):
    name = "my_service"

    redis = Redis('redis')

    @rpc
    def hello(self, name):
        self.redis.set("foo", name)
        return "Hello, {}!".format(name)

    @rpc
    def bye(self):
        name = self.redis.get("foo")
        return "Bye, {}!".format(name)


config = {
    'REDIS_URIS': {'redis': 'redis://127.0.0.1:32768/10'},
    'AMQP_URI': 'pyamqp://guest:guest@localhost',
    'WEB_SERVER_ADDRESS': '0.0.0.0:8000',
    'rpc_exchange': 'nameko-rpc',
    'max_workers': 10,
    'parent_calls_tracked': 10
}
runner = ServiceRunner(config=config)
runner.add_service(MyService)
runner.start()

can you maybe provide a code for your services?

@staskuban
Copy link
Author

Yes, of course

from nameko_redis import Redis
from nameko.rpc import rpc

class MyService:
    name = "myService"
    
    redis = Redis('redis')

    @rpc
    def register(self, value):
        return True

@etataurov
Copy link
Owner

@staskuban I looked at your code and traceback and looks like even though you've defined your own service runner, you still run your service with nameko run.

Custom service runner seems to require more complicated logic (see example from nameko CLI run https://github.com/nameko/nameko/blob/cc13802d8afb059419384e2e2016bae7fe1415ce/nameko/cli/run.py#L116 )

If you want to run your service with nameko run you need to make sure the config is passed via --config https://nameko.readthedocs.io/en/stable/cli.html#running-a-service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants