def image_service(config): image_svc = ServiceContainer(ImageService, config) replace_dependencies(image_svc, 'image_host') image_svc.start() yield image_svc image_svc.stop()
def it_should_destroy_connection_on_close(self, bs): container = ServiceContainer(ExampleService, {}) container.start() assert bs.Connection.called container.stop() assert bs.Connection.return_value.close.called
def test_hello_languages(language, greeting, rabbit_config): container = ServiceContainer(HelloService, rabbit_config) container.start() context_data = {'language': language} with entrypoint_hook(container, 'hello', context_data) as hook: assert hook("Matt") == "{}, Matt!".format(greeting) container.stop()
def test_update_is_called_when_battle_finishes(rabbit_config): container = ServiceContainer(ScoreService, rabbit_config) container.start() dispatch = event_dispatcher(rabbit_config) with mock.patch.object(ScoreService, 'update_players_score') as mock_method: with entrypoint_waiter(container, 'update_players_score'): dispatch('battle_service', 'battle_finished', [0, 1, 2]) mock_method.assert_called_once_with([0, 1, 2]) container.stop()
def test_event_interface(rabbit_config): container = ServiceContainer(ServiceB, rabbit_config) container.start() dispatch = event_dispatcher(rabbit_config) # prints "service b received payload" before "exited" with entrypoint_waiter(container, 'handle_event'): dispatch("service_a", "event_type", "payload") print "exited" container.stop()
#!/usr/bin/env python3 import time import eventlet eventlet.monkey_patch() from nameko.containers import ServiceContainer from nameko_services.sample_server import SampleServer AMQP_URI = "pyamqp://*****:*****@localhost" if __name__ == '__main__': container = ServiceContainer(SampleServer, config={'AMQP_URI': AMQP_URI}) service_extensions = list(container.extensions) container.start() print("started") while True: try: time.sleep(1) except KeyboardInterrupt: print("Keyboard interrupt occurred") break container.stop()
import eventlet from RPi import GPIO from nameko.containers import ServiceContainer from config import rabbit_config, rpc_proxy, ServicesNames from senses_service.temperature_service import TemperatureService eventlet.monkey_patch() service_container = ServiceContainer(TemperatureService, config=rabbit_config) service_container.start() try: with rpc_proxy(ServicesNames.TEMPERATURE_SERVICE) as rpc: while True: rpc.update_temperature() eventlet.sleep(30) except KeyboardInterrupt: print('KeyboardInterrupt exception') finally: GPIO.cleanup() service_container.stop() print('GPIO cleanup') print('Stopping services')
from nameko.containers import ServiceContainer class Service(object): name = "service" # create a container container = ServiceContainer(Service, config={}) # ``container.extensions`` exposes all extensions used by the service service_extensions = list(container.extensions) # start service container.start() # stop service container.stop()