# Fedora Messaging Task 1. Install fedora messaging using pip. Inside virtual environment. > pip install fedora-messaging 2. Install and run rabbitmq. > sudo apt-get install rabbitmq-server > sudo service rabbitmq-server start 3. Enable web interface > sudo rabbitmq-plugins enable rabbitmq_management ![](https://i.imgur.com/fPd8S6k.png) 4. Login with the credentials ![](https://i.imgur.com/wcZLnMe.png) 5. Create fedora.toml file with the following sample configration. ``` # A basic configuration for Fedora's message broker, using the example callback # which simply prints messages to standard output. # # This file is in the TOML format. amqp_url = "amqps://fedora:@rabbitmq.fedoraproject.org/%2Fpublic_pubsub" # callback = "fedora_messaging.example:printer" [tls] ca_cert = "cacert.pem" keyfile = "fedora-key.pem" certfile = "fedora-cert.pem" [client_properties] app = "Fedora Messaging Application" # Some suggested extra fields: # URL of the project that provides this consumer app_url = "https://github.com/fedora-infra/fedora-messaging" # Contact emails for the maintainer(s) of the consumer - in case the # broker admin needs to contact them, for e.g. app_contacts_email = ["jcline@fedoraproject.org"] # [exchanges."amq.topic"] # type = "topic" # durable = true # auto_delete = false # arguments = {} # Queue names *must* be in the normal UUID format: run "uuidgen" and use the # output as your queue name. If your queue is not exclusive, anyone can connect # and consume from it, causing you to miss messages, so do not share your queue # name. Any queues that are not auto-deleted on disconnect are garbage-collected # after approximately one hour. # # If you require a stronger guarantee about delivery, please talk to Fedora's # Infrastructure team. [queues.00000000-0000-0000-0000-000000000000] durable = false auto_delete = true exclusive = true arguments = {} # [[bindings]] # queue = "00000000-0000-0000-0000-000000000000" # exchange = "amq.topic" # routing_keys = ["#"] # Set this to the specific topics you are interested in. [consumer_config] example_key = "for my consumer" [qos] prefetch_size = 0 prefetch_count = 25 [log_config] version = 1 disable_existing_loggers = true [log_config.formatters.simple] format = "[%(levelname)s %(name)s] %(message)s" [log_config.handlers.console] class = "logging.StreamHandler" formatter = "simple" stream = "ext://sys.stdout" [log_config.loggers.fedora_messaging] level = "INFO" propagate = false handlers = ["console"] [log_config.loggers.twisted] level = "INFO" propagate = false handlers = ["console"] [log_config.loggers.pika] level = "WARNING" propagate = false handlers = ["console"] # If your consumer sets up a logger, you must add a configuration for it # here in order for the messages to show up. e.g. if it set up a logger # called 'example_printer', you could do: #[log_config.loggers.example_printer] #level = "INFO" #propagate = false #handlers = ["console"] [log_config.root] level = "ERROR" handlers = ["console"] ``` NOTE - Change the path of ca_cert, keyfile, certfile based on filepath in your system. 5. Create a file publish.py to publish the message. Save the file and give the needed file permissions. > chmod +x publish.py ```#!/usr/bin/env python3 from fedora_messaging.api import publish, Message from fedora_messaging.config import conf conf.setup_logging() message = Message( topic="tutorial.topic", body={"Hello": "World"} ) publish(message) ``` 6. Likewise create another file consume.py with the below mentioned code snippet. Give the file permissions. > chmod +x consume.py ```#!/usr/bin/env python3 from fedora_messaging.api import consume from fedora_messaging.config import conf def print_message(message): print(message) if __name__ == "__main__": conf.setup_logging() consume(print_message) ``` 7. Open two terminals. Run the consume.py file first using ./consume.py on one, so that it keeps listening. 8. On another terminal, run command ./publish.py. 9. Output - Now, you'll see the topic, header, message that was being published appear on the terminal where consume.py is listening. Shows the output of ./consume.py terminal. ![](https://i.imgur.com/Z7Yu2Sz.png) Things to take care of 1. All the needed certification files can be taken from the projects [github repo](https://github.com/fedora-infra/fedora-messaging/tree/master/configs). 2. Before publishing the message make sure that consume.py is already running(listening). Only then you'll be able to see the published messages. Resources 1. Documentation Fedora messaging - https://fedora-messaging.readthedocs.io/en/stable/tutorial/installation.html