이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 52. 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.

52.1. The Message Interface

Overview

An instance of org.apache.camel.Message type can represent any kind of message (In or Out). Figure 52.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 52.1. Message Inheritance Hierarchy

The Message interface

Example 52.1, “Message Interface” shows the definition of the org.apache.camel.Message interface.

Example 52.1. Message Interface

package org.apache.camel;

import java.util.Map;
import java.util.Set;

import javax.activation.DataHandler;

public interface Message {

    String getMessageId();
    void setMessageId(String messageId);

    Exchange getExchange();

    boolean isFault();
    void    setFault(boolean fault);

    Object getHeader(String name);
    Object getHeader(String name, Object defaultValue);
    <T> T getHeader(String name, Class<T> type);
    <T> T getHeader(String name, Object defaultValue, Class<T> type);
    Map<String, Object> getHeaders();
    void setHeader(String name, Object value);
    void setHeaders(Map<String, Object> headers);
    Object  removeHeader(String name);
    boolean removeHeaders(String pattern);
    boolean hasHeaders();

    Object getBody();
    Object getMandatoryBody() throws InvalidPayloadException;
    <T> T  getBody(Class<T> type);
    <T> T  getMandatoryBody(Class<T> type) throws InvalidPayloadException;
    void     setBody(Object body);
    <T> void setBody(Object body, Class<T> type);

    DataHandler getAttachment(String id);
    Map<String, DataHandler> getAttachments();
    Set<String> getAttachmentNames();
    void removeAttachment(String id);
    void addAttachment(String id, DataHandler content);
    void setAttachments(Map<String, DataHandler> attachments);
    boolean hasAttachments();

    Message copy();

    void copyFrom(Message message);

    String createExchangeId();
}
Copy to Clipboard Toggle word wrap

Message methods

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 InvalidPayloadException exception 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.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat