...
/Creating a RabbitMQ Consumer for the Core App
Creating a RabbitMQ Consumer for the Core App
Learn how to create a RabbitMQ consumer in Flask.
We'll cover the following...
After creating the RabbitMQ producer for the Core app, we must also create a RabbitMQ consumer for it.
Creating a consumer in the Core app
To create a RabbitMQ consumer in the Core app, we'll create a file in the backendservice2 app directory folder named consumer.py. Then, we'll open the file and import pika and json, like so:
import pika, json
We also have to import our House model and db from our core.py, as follows:
from core import House, db
After doing this, we can use pika to create a connection and define a callback function to consume our messages, as shown below:
Line 7: We create a variable,
params, which is set topika.URLParameters('{{Your_AMQP_URL}}'). This means we want to connect to a message broker, in this ...