home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

ActiveMQ example source code file (MessageBodyFormatter.java)

This example ActiveMQ source code file (MessageBodyFormatter.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - ActiveMQ tags/keywords

activemqblobmessage, activemqblobmessage, activemqmapmessage, activemqmapmessage, activemqmessage, activemqtextmessage, activemqtextmessage, bytesequence, jmsexception, messagebodyformatter, messagebodyformatter, override, string

The ActiveMQ MessageBodyFormatter.java source code

 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *      http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package org.apache.activemq.store.amq;

import javax.jms.JMSException;

import org.apache.activemq.command.ActiveMQBlobMessage;
import org.apache.activemq.command.ActiveMQBytesMessage;
import org.apache.activemq.command.ActiveMQMapMessage;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.ActiveMQObjectMessage;
import org.apache.activemq.command.ActiveMQStreamMessage;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.activemq.util.ByteSequence;

public class MessageBodyFormatter {
	final ActiveMQMessage message;
	public MessageBodyFormatter(ActiveMQMessage message) {

	public String toString() {
		try {
			switch (message.getDataStructureType()) {
			case ActiveMQMessage.DATA_STRUCTURE_TYPE:
				return "";
			case ActiveMQBlobMessage.DATA_STRUCTURE_TYPE:
				ActiveMQBlobMessage blob = (ActiveMQBlobMessage) message;
				return blob.getRemoteBlobUrl();
			case ActiveMQMapMessage.DATA_STRUCTURE_TYPE:
				ActiveMQMapMessage map = (ActiveMQMapMessage)message;
				return map.getContentMap().toString();			
			case ActiveMQTextMessage.DATA_STRUCTURE_TYPE:
				ActiveMQTextMessage text = (ActiveMQTextMessage)message;
				return text.getText();
			case ActiveMQBytesMessage.DATA_STRUCTURE_TYPE:
			case ActiveMQObjectMessage.DATA_STRUCTURE_TYPE:
			case ActiveMQStreamMessage.DATA_STRUCTURE_TYPE:
				ByteSequence data = message.getContent();
				return "binary payload {length="+data.getLength()+", compressed="+message.isCompressed()+"}";
		} catch (JMSException e) {
		return "";

Other ActiveMQ examples (source code examples)

Here is a short list of links related to this ActiveMQ MessageBodyFormatter.java source code file:

new blog posts


Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.