Home > Software engineering >  How to show full message text in org.apache.activemq.command.ActiveMQTextMessage
How to show full message text in org.apache.activemq.command.ActiveMQTextMessage

Time:12-15

2022-12-14 14:04:56,317 DEBUG [org.apa.cam.com.jms.EndpointMessageListener] (Camel (camel-1) thread #8 - JmsConsumer[my.queue]) activemq://queue:my.queue consumer received JMS message: ActiveMQTextMessage {commandId = 13, responseRequired = true, messageId = ID:xxxx, originalDestination = null,..., content = org.apache.activemq.util.ByteSequence@11ba49fe, ..., text = { "foo": "bar", "x...y": false}}

Notice that text is truncated. How can I see the full text?

EndpointMessageListener has this log line:

LOG.debug("{} consumer received JMS message: {}", this.endpoint, message);

And for message of type javax.jms.Message, the toString() method implementation of org.apache.activemq.command.ActiveMQTextMessage is:

public String toString() {
    try {
        String text = this.text;
        if (text == null) {
            text = this.decodeContent(this.getContent());
        }

        if (text != null) {
            text = MarshallingSupport.truncate64(text);
            HashMap<String, Object> overrideFields = new HashMap();
            overrideFields.put("text", text);
            return super.toString(overrideFields);
        }
    } catch (JMSException var3) {
    }

    return super.toString();
}

where it always truncates to 60 chars.

public static String truncate64(String text) {
    if (text.length() > 63) {
        String var10000 = text.substring(0, 45);
        text = var10000   "..."   text.substring(text.length() - 12);
    }

    return text;
}

Can I find out what the complete message was?

CodePudding user response:

You could for instance test if the received JMSMessage is of type text, and if so, cast it and invoke the getText() method rather than the generic toString():

if ( message instanceof javax.jms.TextMessage) {
  TextMessage tm = (TextMessage) message;
  LOG.debug("{} consumer received JMS message: {}", this.endpoint, tm.getText()); 
}

Beware it may also arrive as Bytes- or Stream-Message

  • Related