Comment 9 for bug 1609766

Revision history for this message
Kirill Bespalov (k-besplv) wrote :

> I think "if not consumer.is_declared(self)" is TRUE only after
> "self._set_current_channel(channel)" has been called;
> so I think declare consumers after "self._set_current_channel(channel)" below is a good idea.

We already do consumer re-declaration in cases of a connection failing in the error callback:

def on_reconnection(new_channel):
      self.set_transport_socket_timeout()
      self._set_current_channel(new_channel)

      for consumer in self._consumers:
         consumer.declare(self)

But the problem that this error callback (on_reconnection) may fail due timeouts,
another connection losing, etc. It also may failed in _set_current_channel(channel) if we move the declaration code there, no difference.

So, in order to 100% make sure that we declared all queues/bindings/exchanges before staring consuming I kept the channel in consumer.declare:

def declare(self, conn):
       ...
            self.queue.declare()
       ...

       self._declared_on = conn.channel

And then in connection.consume() I check this point via is_declared()