使用 Curl 从 Jboss 应用服务器控制台读取 JMS 队列消息计数

使用 Curl 从 Jboss 应用服务器控制台读取 JMS 队列消息计数

我正在使用 Jboss Application Server 7.1.3 Final,我的要求是如果特定 jms 队列中有超过 n 条消息,则提醒管理员采取必要的措施。如果我得到预期的 json 结果,我可以通过 shell 脚本完成。

我尝试了以下命令

curl --digest -D - http://user:userpwd@localhost:9990/management/ --header "Content-Type: application/json" -d '{"operation":"read-resource", "address":["subsystem","messaging","hornetq-server","jms-destinations","jms-queue"], "json.pretty":1}'

并得到以下输出

HTTP/1.1 401 Unauthorized
Content-length: 0
Www-authenticate: Digest realm="ManagementRealm",nonce="22087e300bd9a2a53c37f21bdefe1950"
Date: Mon, 31 Aug 2015 13:02:47 GMT

HTTP/1.1 500 Internal Server Error
Transfer-encoding: chunked
Content-type: application/json
Date: Mon, 31 Aug 2015 13:02:47 GMT
{
    "outcome" : "failed",
    "failure-description" : "JBAS014807: Management resource '[\n    (\"subsystem\" => \"messaging\"),\n    (\"hornetq-server\" => \"jms-destinations\")\n]' not found",
    "rolled-back" : true
}

我的用于消息传递的 Standalone-full.xml 配置:

<subsystem xmlns="urn:jboss:domain:messaging:1.2">
            <hornetq-server>
            <jms-destinations>
                    <jms-queue name="myQueue">
                        <entry name="queue/myQueue"/>
                    </jms-queue>
            </jms-destinations>
            </hornetq-server>
</subsystem>

(其余的 standalone-full.xml 配置已删除)

curl 命令中需要添加什么吗?

答案1

尝试:

# curl -i --digest "http://user:****@localhost:9990/management/subsystem/messaging/hornetq-server/default/jms-queue/myQueue?operation=resource&recursive&include-runtime&json.pretty"

结果

HTTP/1.1 200 OK
Transfer-encoding: chunked
Content-type: application/json
Date: Mon, 31 Aug 2015 14:36:03 GMT

{
    "consumer-count" : 1,
    "dead-letter-address" : "jms.queue.DLQ",
    "delivering-count" : 0,
    "durable" : true,
    "entries" : [
        "queue/myQueue",
        "java:jboss/exported/jms/queue/myQueue"
    ],
    "expiry-address" : "jms.queue.ExpiryQueue",
    "message-count" : 0,
    "messages-added" : 0,
    "paused" : false,
    "queue-address" : "jms.queue.myQueue",
    "scheduled-count" : 0,
    "selector" : null,
    "temporary" : false

}

或者

curl -i --digest 'http://user:*****@localhost:9990/management' --header "Content-Type: application/json" \
    -d '{"operation":"read-resource", "recursive":"true", "include-runtime":"true", "address":["subsystem", "messaging", "hornetq-server", "default", "jms-queue", "myQueue"], "json.pretty":1}'

结果:

HTTP/1.1 200 OK
Transfer-encoding: chunked
Content-type: application/json
Date: Mon, 31 Aug 2015 14:36:03 GMT

{
    "outcome" : "success",
    "result" : {
        "consumer-count" : 1,
        "dead-letter-address" : "jms.queue.DLQ",
        "delivering-count" : 0,
        "durable" : true,
        "entries" : [
            "queue/myQueue",
            "java:jboss/exported/jms/queue/myQueue"
        ],
        "expiry-address" : "jms.queue.ExpiryQueue",
        "message-count" : 0,
        "messages-added" : 0,
        "paused" : false,
        "queue-address" : "jms.queue.myQueue",
        "scheduled-count" : 0,
        "selector" : null,
        "temporary" : false
    }
}

相关内容