title: How to run a rabbitMQ script in a django rest framework project
body: <p>So I have a django rest framework project, and what I want to do, is to push into a rabbitMQ queue some values from a file with a python script, and as soon as my django server starts running, I want the project to start consuming the messages available in the queue, and with those values, insert entities in my database. So here is my producer python script:</p>
  <pre><code>import pika, csv, time
  
  url = 'queue_url'
  params = pika.URLParameters(url)
  connection = pika.BlockingConnection(params)
  channel = connection.channel()
  channel.queue_declare(queue='hello')
  
  with open('sensor.csv', newline='') as csvfile:
      reader = csv.reader(csvfile, delimiter='\n')
      for row in reader:
          channel.basic_publish(exchange='', routing_key='hello', body=row[0])
          print(row[0])
          time.sleep(1)
  
  connection.close()
  </code></pre>
  <p>This script doesn't belong to the django project, I will run this script outside of it. This is my consumer script:</p>
  <pre><code>import pika
  from app.models import Measurement
  
  url = 'queue_url'
  params = pika.URLParameters(url)
  connection = pika.BlockingConnection(params)
  channel = connection.channel()
  channel.queue_declare(queue='hello')
  
  def callback(ch, method, properties, body):
      measurement = Measurement.objects.create(sensor=3, energy_consumption=float(str(body)))   
      measurement.save()
  
  channel.basic_consume('hello',
                        callback,
                        auto_ack=True)
  
  channel.start_consuming()
  connection.close()
  </code></pre>
  <p>I want to integrate this consumer script inside my django project, so that as soon as I start putting messages in my queue with the procuder script, the consumer script is ready for them, intercepts them and inserts a new entity for each value. I have put the consumer script inside one of my applications in my project, but it doesn't seem to be connected to my project. Like, when I save the changes the server doesn't refresh at all, but when I save chenges to any other file, the server refreshes. This is my Measurement model:</p>
  <pre><code>class Measurement(models.Model):
      timestamp = models.DateTimeField(auto_now_add=True)
      energy_consumption = models.FloatField()
      sensor = models.ForeignKey(Sensor, on_delete=models.CASCADE, null=True)
  </code></pre>
  <p>The values in the queue are the energy_consumption, and when I read a value from the queue I want to create a new instance of measurement in my database.</p>