Multiple service subscription

Hi,
I have a question about event subscription. Let’s say I have an exception tracking service. Is there an easy way with the event API to make it subscribe to any services that would publish an ‘exception’ event so that I don’t have to re-deploy it if I add a new service in my application ?

Thanks
Jpk.

Nameko Events doesn’t support this kind of “wildcard” subscription. You subscribe to a particular event type from a particular service.

However, Nameko Events is just a particular way of using the underlying Publisher and Consumer extensions. You can implement the pattern you want with that pair.

Runnable example:

from nameko.messaging import Publisher, consume
from nameko.timer import timer

from kombu import Exchange, Queue


exception_exchange = Exchange("exceptions", type="topic")
exception_queue = Queue("exceptions_queue", exchange=exception_exchange, routing_key="*.exception")


class ServiceA:
    name = "a"

    publish = Publisher()

    @timer(interval=1)
    def throws(self):
        self.publish("a: foo", exchange="exceptions", routing_key="a.exception")


class ServiceB:
    name = "b"

    publish = Publisher()

    @timer(interval=2)
    def throws(self):
        self.publish("b: bar", exchange="exceptions", routing_key="b.exception")


class ServiceC:
    name = "c"

    publish = Publisher()

    @timer(interval=3)
    def throws(self):
        self.publish("c: baz", exchange="exceptions", routing_key="c.exception")


class ExceptionTracker:
    name = "tracker"

    @consume(exception_queue)
    def handle_exception(self, payload):
        # consume decorator doesn't expose the underlying routing key,
        # but you could always just put that in the payload
        print("error in service:", payload)

Thanks a lot. :sunglasses: