Configuration improvements
Global config
object
The new nameko.config
dictionary allows you to access service configuration at any time, including service class definition:
from nameko.messaging import Consumer
from nameko import config
class Service:
@consume(
queue=Queue(
exchange=config["MY_EXCHANGE"],
routing_key=config["MY_ROUTING_KEY"],
name=config["MY_QUEUE_NAME"]
),
prefetch_count=config["MY_CONSUMER_PREFETCH_COUNT"]
)
def consume(self, payload):
pass
As you can see having config available outside service container also helps with configuring entrypoints and dependency providers by passing options to their constructors:
from nameko import config
from nameko_sqlalchemy import Database
class Service:
db = Database(engine_options=config["DB_ENGINE_OPTIONS"])
Declaration of config in the CLI
Sometimes it’s helpful to define config entries on the fly when running a service or shell: