RabbitMQ:如何 delete/move 来自 curl 队列中的消息

RabbitMQ: How to delete/move messages in queue from curl

我有多个 RabbitMQ 服务器。

我需要一个界面(带有 JSP),我可以在其中管理(删除 queues/exchanges/messages)所有这些服务器。

我将在内部调用 curl 命令来执行操作。

示例:创建队列

curl -i -u test:test -H "content-type:application/json" \
    -XPUT -d'{"type":"direct","durable":true}' \
    http://192.168.0.30:15672/api/queues/%2f/myQueue

如何使用 curl 在队列中 delete/move 消息?

RabbitMQ 没有直接从队列中删除消息的概念。使用 RabbitMQ 时,有许多不同的方法可以从队列中执行相当于 "deleting" 或 "moving" 消息的操作。使用 REST api,您可以使用这些选项中的每一个。您可以使用队列外的消息,也可以使队列中的消息过期。

使用队列中的消息非常简单,并且有示例here. To use expiry via Time To Live or Size of the queue you can set up a RabbitMQ policy. The documentation for RabbitMQ policies is here.

我的问题的答案位于

https://groups.google.com/d/msg/rabbitmq-users/IS-3v4qNduw/oPseA7VxEgAJ

用卷曲创建的铲子就可以完成工作:

curl 
-u  "user:password" 
-vvv 'http://localhost:15672/api/parameters/shovel/%2Foms/Move%20from%20sourceQueue' 
-X PUT 
-H 'content-type: application/json' 
--data-binary '
{
    "component": "shovel",
    "vhost": "/vhost",
    "name": "Move from sourceQueue",
    "value": {
        "src-uri": "amqp:///%2Fvhost",
        "src-queue": "sourceQueue",
        "src-protocol": "amqp091",
        "src-prefetch-count": 1000,
        "src-delete-after": "queue-length",
        "dest-protocol": "amqp091",
        "dest-uri": "amqp:///%2Fvhost",
        "dest-add-forward-headers": false,
        "ack-mode": "on-confirm",
        "dest-queue": "destQueue"
    }
}
' --compressed