gmr / rabbitpy

A pure python, thread-safe, minimalistic and pythonic RabbitMQ client library
http://rabbitpy.readthedocs.org
BSD 3-Clause "New" or "Revised" License
242 stars 58 forks source link

How do I properly tear down a connection? #102

Closed fake-name closed 7 years ago

fake-name commented 8 years ago

Every time I disconnect, it produces a warning on the rabbitmq server:

=INFO REPORT==== 15-Jul-2016::07:32:45 ===
accepting AMQP connection <0.3832.439> (<snip>:39133 -> <snip>:5671)

=WARNING REPORT==== 15-Jul-2016::07:32:51 ===
closing AMQP connection <0.3832.439> (<snip>:39133 -> <snip>:5671):
client unexpectedly closed TCP connection

This is with a absolutely minimal test-script:

import urllib.parse
import logging
import threading
import time
import json

import rabbitpy

def test_disconnect():

    config = json.load(open("test_conf.json"))

    qs = urllib.parse.urlencode({
        'cacertfile'           : config['sslopts']['ca_certs'],
        'certfile'             : config['sslopts']['certfile'],
        'keyfile'              : config['sslopts']['keyfile'],

        'verify'               : 'ignore',
        'heartbeat'            : 15,

        'connection_timeout'   : 60,

        })

    uri = '{scheme}://{username}:{password}@{host}:{port}/{virtual_host}?{query_str}'.format(
        scheme       = 'amqps',
        username     = config['userid'],
        password     = config['password'],
        host         = config['host'].split(":")[0],
        port         = config['host'].split(":")[1],
        virtual_host = config['vhost'],
        query_str    = qs,
        )

    connection = rabbitpy.Connection(uri)
    time.sleep(5)
    connection.close()

def test():
    import sys
    import os.path
    logging.basicConfig(level=logging.INFO)
    test_disconnect()

if __name__ == "__main__":
    test()

How can I close a connection without producing server warnings?

gmr commented 7 years ago

Thanks for the report, this has been cleaned up for 1.0