Search code examples
rabbitmqpikapython-pika

how to force close a client connection rabbitmq


I have a client server application that uses rabbitmq broker. Client connects to rabbitmq and send messages to server. At some point if server decides that this client should not be connected to rabbitmq i want to be able to force disconnect client from rabbitmq border. Note that in my case I don't want to send message to client to disconnect, on server side I want to just force disconnect this client from rabbitmq.

Couldn't find api to do this. Any help is appriciated.


Solution

  • You can use the management console plug-in in two ways:

    1. Manually, going to the connection and "force close".

    1. Through the HTTP API using "delete" /api/connections/name, here an python example:
    import urllib2, base64
    def calljsonAPI(rabbitmqhost, api):
        request = urllib2.Request("http://" + rabbitmqhost + ":15672/api/" + api);
        base64string = base64.encodestring('%s:%s' % ('guest', 'guest')).replace('\n', '')
        request.add_header("Authorization", "Basic %s" % base64string);
        request.get_method = lambda: 'DELETE';
        urllib2.urlopen(request);
    if __name__ == '__main__':
        RabbitmqHost = "localhost";
        #here you should get the connection detail through the api, 
       calljsonAPI(RabbitmqHost, "connections/127.0.0.1%3A49258%20-%3E%20127.0.0.1%3A5672");