[Twisted-Python] Problem with txampq_helper ampqFactory: closing connections
![](https://secure.gravatar.com/avatar/917e9407f1027d3e6e4bc1a16d49b632.jpg?s=120&d=mm&r=g)
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()? Do I need to unregisterProducer() first (in ampqFactory, i see stuff like resumeProducing() so I assume it is a producer) Cheers, Andrew
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 29 Jan, 10:11 pm, andrewfr_ice@yahoo.com wrote:
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
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 29 Jan, 10:11 pm, andrewfr_ice@yahoo.com wrote:
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
participants (2)
-
Andrew Francis
-
exarkun@twistedmatrix.com