【问题标题】:ActiveMQ Jolokia API How can I get the full Message BodyActiveMQ Jolokia API 如何获取完整的消息正文
【发布时间】:2015-02-26 17:17:57
【问题描述】:

我想编写自己的 ActiveMQ 监视器。我可以从队列中获取队列和消息。但是消息体(内容)被缩短了。如何获取完整的消息正文?

这个我已经测试过了:

获取:Always errors

http://localhost:8161/api/jolokia/exec/org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=errors/browseMessages(java.lang.String)/JMSMessageID%3D%27ID%3AW530-62766-1419849619826-0%3A15%3A1%3A1%3A1%27

http://localhost:8161/api/jolokia/exec/org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=errors/browseMessages(java.lang.String)/JMSMessageID='ID:W530-62766-1419849619826-0:15:1:1:1'

有帖子:

http://localhost:8161/api/jolokia/?ignoreErrors=true&canonicalNaming=false
{
"type":"exec",
"mbean":"org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=errors",
"operation":"browseMessages(java.lang.String)",
"arguments":["JMSMessageID='ID:W530-62766-1419849619826-0:15:1:1:1'"],
}

错误:java.lang.OutOfMemoryError: Java heap space

http://localhost:8161/api/jolokia/?ignoreErrors=true&canonicalNaming=false
{
"type":"exec",
"mbean":"org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=errors",
"operation":"browseMessages(java.lang.String)",
"arguments":["JMSMessageID='ID:W530-62766-1419849619826-0:15:1:1:1'"],
"path":"content"
}

错误:java.lang.NumberFormatException : For input string: "content"

我能工作的唯一方法是每个帖子:

http://localhost:8161/api/jolokia/?maxDepth=7&maxCollectionSize=500&ignoreErrors=true&canonicalNaming=false 
{
"type":"exec",
"mbean":"org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=errors",
"operation":"browseMessages(java.lang.String)",
"arguments":["JMSMessageID='ID:W530-62766-1419849619826-0:15:1:1:1'"],
}

但是我只得到前 500 个字符

感谢您的帮助

【问题讨论】:

  • 看起来您正在使用 jolokia api - 管理 API。不是 activemq REST API。在这里查看:activemq.apache.org/rest.html
  • 是的,/api/message 不起作用
  • 为什么不起作用?你收到什么错误? jolokia api 并不适用于您正在寻找的消息交互方式。
  • 哦,我是 ActiveMQ 的新手,并且正在运行默认配置。在 /api/messages 上,我每次都会收到 404
  • 看看 hawtio 是如何做到这一点的,它能够使用 jolokia 作为其 REST API 浏览具有完整内容的 JMX 消息 - github.com/hawtio/hawtio/blob/master/hawtio-web/src/main/webapp/…

标签: java activemq jmx jolokia


【解决方案1】:

基于cmets,留给大家解答。

Jolokia API 是一个管理 API,而不是一个消息消费 API。 ActiveMQ 项目提供了一个绑定到/api/message 的 REST API 供用户使用。

完整的 API 细节可以在这里找到:http://activemq.apache.org/rest.html

假设您有一个名为“ERRORS”的队列,并且 ActiveMQ 在默认配置上运行。你可以POST到这个网址:http://localhost:8161/api/message/ERRORS?type=queue添加消息。请以完整格式查看他们的文档。然后,您可以通过在同一 URL 上执行 GET 来读取此队列中的消息:http://localhost:8161/api/message/ERRORS?type=queue

默认情况下,您需要为每个操作传递身份验证信息。

【讨论】:

  • 我不想创建消费者!消息应该留在那里。我只想看到消息和消息信息,但我不想消费消息。
【解决方案2】:

对我有用,不会影响队列状态,这是一个目标:

#! /bin/bash

url="http://localhost:8161/api/jolokia/?maxDepth=10&maxCollectionSize=1000&ignoreErrors=true"
u='admin:admin'

q='orders.input'
m="org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=$q"

l="curl.log"

s='"operation":"browseMessages()"'
d='{"type":"exec", "mbean":"'"$m"'", '"$s"'}'
jq='[.value[].jMSMessageID]'
sed="s/^  \"ID:([a-zA-Z0-9_:-]{10,})\",?$/\1/p"
ids="`curl -u \"$u\" --stderr \"$l\" -d \"$d\" \"$url\" |jq \"$jq\" |sed -rn \"$sed\"`"

jq='[{"time": .value.JMSTimestamp, "id": .value.JMSMessageID, "msg": .value.Text}]'
d="{\"type\":\"exec\", \"mbean\":\"$m\", \"operation\":\"getMessage(java.lang.String)\", \"arguments\":[\"ID:X\"]}"
echo "$ids" |xargs -iX curl -u "$u" --stderr "$l" -d "$d" "$url" |jq "$jq"

【讨论】:

    猜你喜欢
    • 2018-01-17
    • 2015-11-19
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 2013-10-25
    • 2018-02-03
    • 1970-01-01
    相关资源
    最近更新 更多