# Multiple service subscription

**URL:** <https://discourse.nameko.io/t/multiple-service-subscription/637>\
**Category:** Uncategorized\
**Created:** [October 21, 2020, 2:46pm UTC](https://discourse.nameko.io/t/multiple-service-subscription/637 "2020-10-21T14:46:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jpk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/jpk/32/123_2.png) [@Jpk](https://discourse.nameko.io/u/Jpk)\
**Post date:** [October 21, 2020, 2:46pm UTC](https://discourse.nameko.io/t/multiple-service-subscription/637/1 "2020-10-21T14:46:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [December 1, 2020, 9:57pm UTC](https://discourse.nameko.io/t/multiple-service-subscription/637/2 "2020-12-01T21:57:11Z")

</div>

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:

```auto
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)
```

---

<div class="post-metadata">

**Author:** ![Jpk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/jpk/32/123_2.png) [@Jpk](https://discourse.nameko.io/u/Jpk)\
**Post date:** [December 2, 2020, 9:06am UTC](https://discourse.nameko.io/t/multiple-service-subscription/637/3 "2020-12-02T09:06:47Z")

</div>

Thanks a lot. 🕶
