| 113 | self.connection.ioloop.call_later(5, self.connection.ioloop.stop) |
| 114 | |
| 115 | def create_consumers(self): |
| 116 | ssl_options = None |
| 117 | if settings.RABBITMQ_USE_SSL: |
| 118 | ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) |
| 119 | ssl_context.set_ciphers('ECDHE+AESGCM:!ECDSA') |
| 120 | ssl_options = pika.SSLOptions(context = ssl_context) |
| 121 | self.connection = pika.SelectConnection( |
| 122 | pika.ConnectionParameters(host = settings.RABBITMQ_HOST, |
| 123 | port = settings.RABBITMQ_PORT, |
| 124 | ssl_options = ssl_options, |
| 125 | heartbeat = 10, |
| 126 | credentials = pika.PlainCredentials(settings.RABBITMQ_DEFAULT_USER, |
| 127 | settings.RABBITMQ_DEFAULT_PASS)), |
| 128 | on_open_callback = self.on_connection_open, |
| 129 | on_open_error_callback = self.on_connection_open_error, |
| 130 | on_close_callback = self.on_connection_closed |
| 131 | ) |
| 132 | |
| 133 | def run(self): |
| 134 | """Run the example code by connecting and then starting the IOLoop. |