CJWorkbench / carehare

Async RabbitMQ client that handles all the edge cases
MIT License
4 stars 0 forks source link

How can I add priority to my message on publish? #8

Open RonnyPixel opened 2 months ago

RonnyPixel commented 2 months ago

It seems publish(self, message: 'bytes', *, exchange_name: 'str' = '', routing_key: 'str' = '') only have these arguments, and from what I've read the priority is encoded in the message header not body so how can I send a message with a certain priority?

adamhooper commented 2 months ago

Great question. We'd need a PR! (I have no time to code, but I will review and cut a release if need be.)

This library uses pamqp under the hood. I think it might make sense to wrap (or expose) the pamqp Properties class, so properties could be passed as an optional parameter to publish(). It would go in the ContentHeader here https://github.com/CJWorkbench/carehare/blob/1ecbd99676256df3472b81968d5d325a44b19db4/carehare/_exchange_channel.py#L88.

My preference is wrapping the Properties class (i.e., creating a carehare.PublishProperties type that contains only the stuff we know we want). But I'd entertain exposing pamqp, maybe, if the rationale is strong.

RonnyPixel commented 2 months ago

Thank you for the quick response! It's a very nice lightweight API you have made, but I'm not so proficient in python so I think I'll just switch to pika then, it seems they have exposed properties=pika.BasicProperties(priority=i)) already