[Twisted-Python] Problem with txampq_helper ampqFactory: closing connections
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Thu Jan 30 05:06:54 MST 2014
On 29 Jan, 10:11 pm, andrewfr_ice at yahoo.com wrote:
>Hi Folks:
>
>I need to maintain a programme that uses txampq_helper library
>ampqFactory. The current program does not close the connection to the
>underlying rabbitmq (the code is a mess).
>
>Can I simple call theampqFactory.protocol.transport.loseConnection()?
Does this factory keep a reference to a connected protocol as its
`protocol` attribute? Most factories keep a reference to their protocol
class there.
If it isn't keeping a reference to the instance then you won't be able
to disconnect it this way, you'll have to find a reference to it some
other way.
One easy way to do this is to wrap the factory with `WrappingFactory`
from `twisted.protocols.policies`. This factory keeps a `protocols`
dictionary on itself tracking all of the currently-connected protocols
it (and the wrapped factory) have been used to create.
>Do I need to unregisterProducer() first (in ampqFactory, i see stuff
>like resumeProducing() so I assume it is a producer)
You do need to unregister, yes. Alternatively, you can use
`abortConnection` as long as the transport you're using has implemented
that method (and as long as you don't care if some bytes in the send
buffer get dropped).
Jean-Paul
More information about the Twisted-Python
mailing list