# Can we use multiple events handler and get event type?

**URL:** <https://discourse.nameko.io/t/can-we-use-multiple-events-handler-and-get-event-type/617>\
**Category:** Uncategorized\
**Created:** [July 11, 2020, 10:23am UTC](https://discourse.nameko.io/t/can-we-use-multiple-events-handler-and-get-event-type/617 "2020-07-11T10:23:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![h0rn3t](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/h0rn3t/32/106_2.png) [@h0rn3t](https://discourse.nameko.io/u/h0rn3t)\
**Post date:** [July 11, 2020, 10:23am UTC](https://discourse.nameko.io/t/can-we-use-multiple-events-handler-and-get-event-type/617/1 "2020-07-11T10:23:08Z")

</div>

```
class Service:
 
    name = "service"
    @event_handler("main_dispatcher", "vendor1.event1")
    @event_handler("main_dispatcher", "vendro2.event1")
    @event_handler("main_dispatcher", "vendro2.event2")
    def parse(self, body):
        if event_type == 'vendro2.event1":
            params = vendro2.parse(body)

```

I need to process a few events in one Service, can anyone show right way for this ?

---

<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:** [July 11, 2020, 7:56pm UTC](https://discourse.nameko.io/t/can-we-use-multiple-events-handler-and-get-event-type/617/2 "2020-07-11T19:56:28Z")

</div>

The `event_handler` API is slightly annoying in not supporting this.

Your options are either to declare a common method body, and a wrapper method for each handler you want, or use partials.

i.e.

```auto
class Service:
    name = "service"

    @event_handler("main_dispatcher", "vendor1.event1")
    def vendor1_event1(self, body):
        self.base(body, type="vendor1.event1")
        
    @event_handler("main_dispatcher", "vendor1.event1")
    def vendor2_event1(self, body):
        self.base(body, type="vendor2.event1")

    def base(self, body, type):
        ...

```

or.

```auto
handle_vendor1_event1 = partial(event_handler, "vendor1.event1")
handle_vendor2_event1 = partial(event_handler, "vendor2.event1")

class Service:
    name = "service"

    @handle_vendor1_event1
    @handle_vendor2_event1
    def handle(self, type, body):
        ...

```

I haven’t actually tested the latter but I think it would work.

I would probably favour the first approach

---

<div class="post-metadata">

**Author:** ![h0rn3t](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/h0rn3t/32/106_2.png) [@h0rn3t](https://discourse.nameko.io/u/h0rn3t)\
**Post date:** [July 11, 2020, 9:20pm UTC](https://discourse.nameko.io/t/can-we-use-multiple-events-handler-and-get-event-type/617/3 "2020-07-11T21:20:22Z")

</div>

thanks, will try, BTW second looks more pretty
