Re: How to consume fedora-messaging?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 6/20/19 4:11 AM, Pavel Raiskup wrote:
Hi Adam, or anyone,

On Monday, June 10, 2019 6:06:42 PM CEST Adam Williamson wrote:
If you're writing an AMQP consumer in Python, what you'll ultimately
get for your consumer to process is a `message` object which is an
instance of a fedora_messaging.api.Message() (or a subclass of it - a
message schema class).

I fail to see an example of this, I mean ...  [1] says

     Message bodies are JSON objects, that adhere to a schema. Message schemas
     live in their own Python package, so they can be installed on the producer
     and on the consumer.

do we have any such package so I (as a consumer) can install the package
with schema class, and use it to parse the message body?  I have seen
the example of producing the message using the schema [2], but not
consuming - only the toy example which is not really using the schema
class.

Only if the publisher of the message has created a schema. There are a
couple at this point, but not many. The consumer will log (at warning
level) if a message arrived that indicates it has a schema and you don't
have it installed. It doesn't give you a ton of information how to find that schema, though, so I filed an issue[0] to fix that.

You can try it out with Bodhi's[1] messages, for example.


This will have a `body` attribute which should be a dict of the message
'body' - the main meat of the message.

... I can use the "meat" to instantiate the message object manually, by
Message(body=body) perhaps, but I still have to first check the topic,
etc, I hoped there's something like:

   from MYAPP import MessageConsumer
   from fedora_messaging.api import consume
   ...

   class Consumer(MessageConsumer):
       def consume(self, message):
           """ message _is_ instance of the schema class """
           message.do_some_stuff()
           if message.some_property:
               do_something()

   consume(Consumer)


This example wouldn't work because you're not passing the actual
callable, but that issue aside, your consumer gets an instance of
the Message class or one of its sub-classes. The Message class is
used if the publisher used it or if you don't have the schema
available.


[0] https://github.com/fedora-infra/fedora-messaging/issues/187
[1] https://pypi.org/project/bodhi-messages/

- Jeremy
_______________________________________________
infrastructure mailing list -- infrastructure@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to infrastructure-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/infrastructure@xxxxxxxxxxxxxxxxxxxxxxx




[Index of Archives]     [Fedora Development]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]

  Powered by Linux