【问题标题】:how to force close a client connection rabbitmq如何强制关闭客户端连接rabbitmq
【发布时间】:2015-09-05 08:05:05
【问题描述】:

我有一个使用 rabbitmq 代理的客户端服务器应用程序。 客户端连接到rabbitmq并向服务器发送消息。在某些时候,如果服务器决定此客户端不应连接到 rabbitmq,我希望能够强制断开客户端与 rabbitmq 边界的连接。 请注意,在我的情况下,我不想向客户端发送消息以断开连接,在服务器端我只想强制将此客户端与 rabbitmq 断开连接。

找不到执行此操作的 api。任何帮助都会得到帮助。

【问题讨论】:

    标签: rabbitmq pika python-pika


    【解决方案1】:

    您可以通过两种方式使用管理console plug-in:

    1. 手动,转到连接并“强制关闭”。

    1. 通过HTTP API 使用“删除”/api/connections/name,这里是一个python 示例:
    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");
    

    【讨论】:

    • 我想以编程方式关闭连接,http api似乎可行,普通api有办法吗?
    • 修改了答案。@user424060
    【解决方案2】:

    您可以使用rabbitmqctl 进行关闭/强制关闭连接:

    rabbitmqctl close_connection <connectionpid> <explanation>
    

    &lt;connectionpid&gt; 来自:

    rabbitmqctl list_connections
    
    #or 
    
    rabbitmqctl list_consumers
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 2013-08-13
      • 1970-01-01
      相关资源
      最近更新 更多