Skip to content

Recovery from ChannelWrongStateError #1433

Closed Answered by colingoodman
colingoodman asked this question in Q&A
Discussion options

You must be logged in to vote

I found a script in a Stack Overflow answer that is similar to the functionality in my script with a key difference being that it works. I made the following change to ensure it will attempt to reconnect until success:

    def connect(self):
        while not self._conn or self._conn.is_closed:
            try:
                t.sleep(0.5)
                self._conn = pika.BlockingConnection(self._params)
                self._channel = self._conn.channel()
                self._channel.exchange_declare(exchange=self.EXCHANGE,
                                           exchange_type=self.TYPE)
            except Exception as e:
                print(e)
                t.sleep(1)

There ar…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@colingoodman
Comment options

@colingoodman
Comment options

Answer selected by colingoodman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants