Hi,
I wanted to ask why at Consumer entrypoint, that will be used as consume
decorator, the RMQ Message that includes info like delivery_info
it’s not included at handle_message. I can see that the callback that gets defined at consume decorator includes only the actual message published to RMQ. To give some background why I have been digging on it, I want to use the same callback method for multiple @consume decorators that each one of them uses different routing key. So I had the idea to use a single callback for DRY reasons and make it generic using routing_key
.
So I have ended up subclassing Consume entrypoint, and overriding it’s handle_message
method by passing both body
and message
as callback’s arguments.
Doing so, I was able to do the following that works as fits my needs:
e = Exchange(name="myexchange", type="topic", durable=True, delivery_mode=2)
class Service:
name = "foo"
@consume(
queue=Queue(name="queue_1", exchange=e, routing_key="rk1"),
prefetch_count=1,
)
@consume(
queue=Queue(name="queue_2", exchange=e, routing_key="rk2"),
prefetch_count=1,
)
def handle_received_message(self, body, message):
print(body) # prints payload published
print(message) # prints Message object, <Message object at 0x7f45f57a0ee0 with details {'state': 'RECEIVED', 'delivery_tag': 1, 'body_length': 9, 'properties': {}, 'delivery_info': {'exchange': 'myexchange', 'routing_key': 'rk1'}}>
Essentially, my question is if it’s OK to do so or have I broken anything internal of nameko?
Thank you in advance for your time and your reply on this.
Spyros