Re: How to consume fedora-messaging?

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

 



On Thu, 2019-06-20 at 10:11 +0200, 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?

Yeah, Bodhi. Write a consumer that listens to Bodhi messages, then run
it without python3-bodhi installed. When it gets a message, it'll just
show up as an instance of Message(), and your system log will have a
warning like this:

Jun 20 14:44:40 openqa-stg01.qa.fedoraproject.org fedora-
messaging[11082]: [WARNING fedora_messaging.message] The schema
"bodhi.update.request.testing.v1" is not in the schema registry! Either
install the package with its schema definition or define a schema.
Falling back to the default schema...

Now install python3-bodhi, run the consumer again, and this time the
message should show up as an instance of the appropriate schema class.
(I have not actually tested this as the consumers I'm writing don't
need to use any of the schema methods really...but that's how it's
supposed to work).

>   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.
> 
> > 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)

Yeah, so long as the package that provides the schema class is
installed, this actually should work. I guess whether you write your
consumer to work with or without the schema class, or just have it blow
up if the schema class is not installed, is kinda up to you.
-- 
Adam Williamson
Fedora QA Community Monkey
IRC: adamw | Twitter: AdamW_Fedora | XMPP: adamw AT happyassassin . net
http://www.happyassassin.net
_______________________________________________
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