Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Chapter 50. Message Interface
Abstract
						This chapter describes how to implement the 
Message interface, which is an optional step in the implementation of a Apache Camel component.
					50.1. The Message Interface
Copy linkLink copied to clipboard!
Overview
Copy linkLink copied to clipboard!
					An instance of 
org.apache.camel.Message type can represent any kind of message (In or Out). Figure 50.1, “Message Inheritance Hierarchy” shows the inheritance hierarchy for the message type. You do not always need to implement a custom message type for a component. In many cases, the default implementation, DefaultMessage, is adequate.
				Figure 50.1. Message Inheritance Hierarchy
The Message interface
Copy linkLink copied to clipboard!
					Example 50.1, “Message Interface” shows the definition of the 
org.apache.camel.Message interface.
				Example 50.1. Message Interface
Message methods
Copy linkLink copied to clipboard!
					The 
Message interface defines the following methods:
				- setMessageId(),- getMessageId()—Getter and setter methods for the message ID. Whether or not you need to use a message ID in your custom component is an implementation detail.
- getExchange()—Returns a reference to the parent exchange object.
- isFault(),- setFault()—Getter and setter methods for the fault flag, which indicates whether or not this message is a fault message.
- getHeader(),- getHeaders(),- setHeader(),- setHeaders(),- removeHeader(),- hasHeaders()—Getter and setter methods for the message headers. In general, these message headers can be used either to store actual header data, or to store miscellaneous metadata.
- getBody(),- getMandatoryBody(),- setBody()—Getter and setter methods for the message body. The getMandatoryBody() accessor guarantees that the returned body is non-null, otherwise the- InvalidPayloadExceptionexception is thrown.
- getAttachment(),- getAttachments(),- getAttachmentNames(),- removeAttachment(),- addAttachment(),- setAttachments(),- hasAttachments()—Methods to get, set, add, and remove attachments.
- copy()—Creates a new, identical (including the message ID) copy of the current custom message object.
- copyFrom()—Copies the complete contents (including the message ID) of the specified generic message object,- message, into the current message instance. Because this method must be able to copy from any message type, it copies the generic message properties, but not the custom properties.
- createExchangeId()—Returns the unique ID for this exchange, if the message implementation is capable of providing an ID; otherwise, return- null.
