Configuration changes
ServiceContainer.config
is deprecated.
Accessing the config via ServiceContainer.config
is deprecated in favor of using the global config object, but continues to exist in order to preserve backwards compatibility.
Accessing config via the global:
from nameko import config
from nameko.extensions import DependencyProvider
class Database(DependencyProvider):
def setup(self):
db_uris = config[DB_URIS_KEY] # <- Nameko 3 way, won't work with Nameko 2!
# ...
Accessing config via the service container:
from nameko.extensions import DependencyProvider
class Database(DependencyProvider):
def setup(self):
db_uris = self.container.config[DB_URIS_KEY] # <- still works, Nameko 2 & 3
# ...
In Nameko 3, this will result in a DeprecationWarning
:
.../nameko/containers.py:173: DeprecationWarning: Use ``nameko.config`` instead.
warnings.warn("Use ``nameko.config`` instead.", DeprecationWarning)
Programmatically running services
Breaking Change!
The following section contains a breaking change.
This section is relevant if you are creating runner programmatically, rather than using the run CLI command.
In Nameko 3, the ServiceContainer
and ServiceRunner
classes do not accept the config
argument anymore. You must update configuration in the global object, with config.patch
or directly:
import nameko
from nameko.containers import ServiceContainer
nameko.config["AMQP_URI"] = "pyamqp://someuser:*****@somehost/"
container = ServiceContainer(Service)
container.start()
# AMQP extensions will connect as someuser to RabbitMQ broker at somehost ...
container.stop()
Same for the runner:
from nameko.runners import ServiceRunner
nameko.config["AMQP_URI"] = "pyamqp://someuser:*****@somehost/"
runner = ServiceRunner()
runner.add_service(ServiceA)
runner.add_service(ServiceB)
runner.start()
# AMQP extensions will connect as someuser to RabbitMQ broker at somehost ...
runner.stop()
Other configuration related changes
- The
--broker
CLI option is deprecated in favour of--define
and--config
.
TODO: doesn’t actually raise a warning anymore
- The built-in
Config
dependency provider is deprecated as the config can be accessed and read directly.