user424060
user424060

Reputation: 1581

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.

Upvotes: 1

Views: 8190

Answers (2)

Hieu Huynh
Hieu Huynh

Reputation: 1083

You can use rabbitmqctl for close/force-close connections:

rabbitmqctl close_connection <connectionpid> <explanation>

<connectionpid> is from:

rabbitmqctl list_connections

#or 

rabbitmqctl list_consumers

Upvotes: 3

Gabriele Santomaggio
Gabriele Santomaggio

Reputation: 22682

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");

Upvotes: 8

Related Questions