Hey Geoff,
I think this is one of the places where the Nameko design is less than
optimal. It would be better if the handling method could inspect the event
type it was handling, but unfortunately it just receives the payload. It's
annoying, but not worth breaking backwards compatibility to change.
You can work around it by subclassing the EventHander entrypoint and
overriding how it handles the incoming message:
# entrypoints.py
from nameko.events import EventHandler as NamekoEventHandler
class EventHandler(NamekoEventHandler):
def handle_message(self, body, message):
args = (self.event_type, body,) # add event type as first arg
kwargs = {}
context_data = self.unpack_message_headers(message)
handle_result = partial(self.handle_result, message)
try:
self.container.spawn_worker(self, args, kwargs,
context_data=context_data,
handle_result=handle_result)
except ContainerBeingKilled:
self.queue_consumer.requeue_message(message)
event_handler = EventHander.decorator
# service.py
from .entrypoints import event_handler
class Service:
@event_handler('service-name', 'event-type')
def handle(self, event_type, event_payload):
...
What was your alternative solution?
ยทยทยท
On Thursday, November 16, 2017 at 4:44:17 PM UTC, juko...@gmail.com wrote:
Once again - I changed how I was 'seeing' the problem, and a different
(more elegant) solution proposed itself