title: RabbitMQ Python Pika - Connection handling for multiple messages
body: <p>I have been reading multiple blogs and documentation about proper setting up RabbitMQ connection for publishing. Below is my scenario</p>
  
  <ul>
  <li>Have few scheduled jobs which execute certain tasks and publish the output to RabbitMQ</li>
  <li>The jobs runs at different time intervals, but the output will be posted to same RabbitMQ queue</li>
  </ul>
  
  <p>The following is the implementation</p>
  
  <pre><code>def get_credentials(self):
      print ("Host ", config_reader.get_lookup_data('RABBITMQ', 'host'))
      credentials = pika.PlainCredentials(config_reader.get_lookup_data('RABBITMQ', 'user'),
                                          config_reader.get_lookup_data('RABBITMQ', 'password'))
      return credentials
  
  def publish_message(self, message):
      print ("Publish message" , message)
      connection = pika.BlockingConnection(
          pika.ConnectionParameters(host=config_reader.get_lookup_data('RABBITMQ', 'host'),
                                    credentials=self.get_credentials()))
      channel = connection.channel()
      channel.exchange_declare(exchange=config_reader.get_lookup_data('RABBITMQ', 'exchange'), passive=True)
      result = channel.queue_declare(exclusive=False,
                                     queue=config_reader.get_lookup_data('RABBITMQ', 'sensor_queue'))
      channel.queue_bind(result.method.queue,
                         exchange=config_reader.get_lookup_data('RABBITMQ', 'exchange'),
                         routing_key=config_reader.get_lookup_data('RABBITMQ', 'routing_key'))
      print ('Publishing message ', message)
      channel.basic_publish(exchange=config_reader.get_lookup_data('RABBITMQ', 'exchange'), body=json.dumps(message),
                            routing_key=config_reader.get_lookup_data('RABBITMQ', 'routing_key'),
                            properties=pika.BasicProperties(
                                headers={'Content-Type': 'application/json'}  # Add a key/value header
                            ))
      print ('published')
  </code></pre>
  
  <p>I observe that the above implementation is every job is establishing a connection and then a channel. I doubt if this type of implementation is causing unnecessary overhead.</p>
  
  <p>Can someone suggest right way to handle the connection object. I personally feel creating connection for every message is certainly overhead</p>