Exemplo n.º 1
0
def event_dispatcher(nameko_config, **kwargs):
    """ Return a function that dispatches nameko events.
    """
    amqp_uri = nameko_config[AMQP_URI_CONFIG_KEY]

    serializer, _ = serialization.setup(nameko_config)
    serializer = kwargs.pop('serializer', serializer)

    ssl = nameko_config.get(AMQP_SSL_CONFIG_KEY)

    # TODO: standalone event dispatcher should accept context event_data
    # and insert a call id

    publisher = Publisher(amqp_uri, serializer=serializer, ssl=ssl, **kwargs)

    def dispatch(service_name, event_type, event_data):
        """ Dispatch an event claiming to originate from `service_name` with
        the given `event_type` and `event_data`.
        """
        exchange = get_event_exchange(service_name)

        publisher.publish(
            event_data,
            exchange=exchange,
            routing_key=event_type
        )

    return dispatch
Exemplo n.º 2
0
def event_dispatcher(nameko_config, **kwargs):
    """ Return a function that dispatches nameko events.
    """
    amqp_uri = nameko_config[AMQP_URI_CONFIG_KEY]

    serializer, _ = serialization.setup(nameko_config)
    serializer = kwargs.pop('serializer', serializer)

    ssl = nameko_config.get(AMQP_SSL_CONFIG_KEY)

    # TODO: standalone event dispatcher should accept context event_data
    # and insert a call id

    publisher = Publisher(amqp_uri, serializer=serializer, ssl=ssl, **kwargs)

    def dispatch(service_name, event_type, event_data):
        """ Dispatch an event claiming to originate from `service_name` with
        the given `event_type` and `event_data`.
        """
        exchange = get_event_exchange(service_name)

        publisher.publish(event_data,
                          exchange=exchange,
                          routing_key=event_type)

    return dispatch
Exemplo n.º 3
0
    def register_provider(self, provider):
        self.provider = provider

        self.serializer, self.accept = serialization.setup(
            provider.container.config)

        self._setup_connection()

        self.queue = provider.queue
        self._setup_consumer()
        self.stopped = False
Exemplo n.º 4
0
    def register_provider(self, provider):
        self.provider = provider

        self.serializer, self.accept = serialization.setup(
            provider.container.config)

        amqp_uri = provider.container.config[AMQP_URI_CONFIG_KEY]
        ssl = provider.container.config.get(AMQP_SSL_CONFIG_KEY)
        self.connection = Connection(amqp_uri, ssl=ssl)

        self.queue = provider.queue
        self._setup_consumer()
        self.stopped = False
Exemplo n.º 5
0
    def register_provider(self, provider):
        self.provider = provider

        self.serializer, self.accept = serialization.setup(
            provider.container.config)

        amqp_uri = provider.container.config[AMQP_URI_CONFIG_KEY]
        ssl = provider.container.config.get(AMQP_SSL_CONFIG_KEY)
        self.connection = Connection(amqp_uri, ssl=ssl)

        self.queue = provider.queue
        self._setup_consumer()
        self.stopped = False
Exemplo n.º 6
0
    def __init__(self, service_cls_list, config):
        self.service_cls_list = service_cls_list
        self.config = config
        self.serializer, self.accept = serialization.setup(self.config)
        self.max_workers = (config.get(MAX_WORKERS_CONFIG_KEY)
                            or DEFAULT_MAX_WORKERS)

        self.shared_extensions = {}
        self.entrypoints = SpawningSet()
        self.dependencies = SpawningSet()
        self.subextensions = SpawningSet()

        self.started = False
        self._worker_pool = GreenPool(size=self.max_workers)

        self._worker_threads = {}
        self._managed_threads = {}
        self._being_killed = False
        self._died = Event()

        for service_cls in service_cls_list:
            self.service_cls = service_cls

            self.service_name = get_service_name(service_cls)

            for attr_name, dependency in inspect.getmembers(
                    service_cls, is_dependency):
                bound = dependency.bind(self.interface, attr_name)
                self.dependencies.add(bound)
                self.subextensions.update(iter_extensions(bound))

            for method_name, method in inspect.getmembers(
                    service_cls, is_method):
                entrypoints = getattr(method, ENTRYPOINT_EXTENSIONS_ATTR, [])
                for entrypoint in entrypoints:
                    bound = entrypoint.bind(self.interface, method_name)
                    self.entrypoints.add(bound)
                    self.subextensions.update(iter_extensions(bound))
Exemplo n.º 7
0
    def __init__(self, service_cls, config):

        self.service_cls = service_cls
        self.config = config

        self.service_name = get_service_name(service_cls)
        self.shared_extensions = {}

        self.max_workers = (
            config.get(MAX_WORKERS_CONFIG_KEY) or DEFAULT_MAX_WORKERS)

        self.serializer, self.accept = serialization.setup(self.config)

        self.entrypoints = SpawningSet()
        self.dependencies = SpawningSet()
        self.subextensions = SpawningSet()

        for attr_name, dependency in inspect.getmembers(service_cls,
                                                        is_dependency):
            bound = dependency.bind(self.interface, attr_name)
            self.dependencies.add(bound)
            self.subextensions.update(iter_extensions(bound))

        for method_name, method in inspect.getmembers(service_cls, is_method):
            entrypoints = getattr(method, ENTRYPOINT_EXTENSIONS_ATTR, [])
            for entrypoint in entrypoints:
                bound = entrypoint.bind(self.interface, method_name)
                self.entrypoints.add(bound)
                self.subextensions.update(iter_extensions(bound))

        self.started = False
        self._worker_pool = GreenPool(size=self.max_workers)

        self._worker_threads = {}
        self._managed_threads = {}
        self._being_killed = False
        self._died = Event()