retry connection setup until succeeds;
This commit is contained in:
parent
af5c419004
commit
d9fe778186
@ -1,7 +1,9 @@
|
|||||||
|
import time
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import pika
|
import pika
|
||||||
|
from pika.exceptions import AMQPConnectionError
|
||||||
|
|
||||||
|
|
||||||
class MBWrapper:
|
class MBWrapper:
|
||||||
@ -79,10 +81,17 @@ class MBWrapper:
|
|||||||
self._connection.close()
|
self._connection.close()
|
||||||
|
|
||||||
def _setup_channel(self):
|
def _setup_channel(self):
|
||||||
self._connection = pika.BlockingConnection(
|
connect_succeeded = False
|
||||||
pika.ConnectionParameters(host=self.host))
|
while not connect_succeeded:
|
||||||
self._channel = self._connection.channel()
|
try:
|
||||||
|
self._connection = pika.BlockingConnection(
|
||||||
|
pika.ConnectionParameters(host=self.host))
|
||||||
|
connect_succeeded = True
|
||||||
|
except pika.exceptions.AMQPConnectionError:
|
||||||
|
print('Could not connect, retry')
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
self._channel = self._connection.channel()
|
||||||
self._channel.exchange_declare(exchange=self.exchange_name, exchange_type=self.exchange_type)
|
self._channel.exchange_declare(exchange=self.exchange_name, exchange_type=self.exchange_type)
|
||||||
|
|
||||||
def _receive(self, ch, method, properties, body):
|
def _receive(self, ch, method, properties, body):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user