6

I want to write my own ActiveMQ Monitor. I can get Queues and Messages from a Queue. But the Message Body (content) is shorted. How can I get the full Message Body?

This I have tested:

Get: 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'

With Post:

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'"],
}

Error: 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"
}

Error: java.lang.NumberFormatException : For input string: "content"

The only way i can i work is per Post:

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'"],
}

But then I get only the first 500 Chars

Thank you for your help

Burner
  • 981
  • 19
  • 41
  • It looks like you're using the jolokia api - the management API. Not the activemq REST API. Check here: http://activemq.apache.org/rest.html – John Ament Dec 30 '14 at 14:36
  • Yes, the /api/message don't work – Burner Dec 30 '14 at 14:42
  • Why doesn't it work? What error do you receive? The jolokia api isn't meant for message interaction the way you're looking for. – John Ament Dec 30 '14 at 14:44
  • Oh, I'm new to ActiveMQ and have the default configuration running. On /api/messages i get every time 404 – Burner Dec 30 '14 at 14:49
  • Check out how hawtio does this, it is able to browse JMX messages with full content using jolokia as its REST API - https://github.com/hawtio/hawtio/blob/master/hawtio-web/src/main/webapp/app/activemq/js/browse.ts – Claus Ibsen Jan 09 '15 at 06:50
  • Where do you find this on hawtIO? I found there also only a preview of 200 Bytes. Not the Full Message! – Burner Jan 09 '15 at 10:53

2 Answers2

1

works for me and doesn't impact the queue state, which was a goal:

#! /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"
Douglas Daseeco
  • 3,475
  • 21
  • 27
-1

Based on comments, leaving this as an answer for you.

The Jolokia API is a management API, not a message consuming API. The ActiveMQ project provides a REST API that is bound to /api/message for users to work with.

The full API details can be found here: http://activemq.apache.org/rest.html

Suppose you have a queue named "ERRORS" and ActiveMQ is running on the default config. You can POST to this URL: http://localhost:8161/api/message/ERRORS?type=queue to add a message. Please see their docs on the full format. You can then read messages from this queue by doing a GET on the same URL: http://localhost:8161/api/message/ERRORS?type=queue

You'll need to pass in authentication information for each operation, by default.

John Ament
  • 11,595
  • 1
  • 36
  • 45
  • 1
    I don't want to create a consumer! The Messages should stay there. I only want to see the Messages and Message Informations, but I don't want to consume the messages. – Burner Dec 30 '14 at 15:10