44장. 메시지 인터페이스

초록

이 장에서는 Apache Camel 구성 요소를 구현하는 선택적 단계인 Message 인터페이스를 구현하는 방법을 설명합니다.

44.1. 메시지 인터페이스

44.1.1. 개요

org.apache.camel.Message 유형의 인스턴스는 모든 종류의 메시지(in 또는 Out)를 나타낼 수 있습니다. 그림 44.1. “메시지 상속 계층 구조” 메시지 유형의 상속 계층 구조를 표시합니다. 구성 요소에 대한 사용자 지정 메시지 유형을 항상 구현할 필요는 없습니다. 대부분의 경우 기본 구현인 DefaultMessage 가 적합합니다.

그림 44.1. 메시지 상속 계층 구조

메시지 상속 계층

44.1.2. 메시지 인터페이스

예 44.1. “메시지 인터페이스” org.apache.camel.Message 인터페이스의 정의를 보여줍니다.

예 44.1. 메시지 인터페이스

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();
}

44.1.3. 메시지 방법

Message 인터페이스는 다음 메서드를 정의합니다.

  • setMessageId(), getMessageId() Cryostat- CryostatGetter 및 메시지 ID에 대한 setter 메서드. 사용자 지정 구성 요소에서 메시지 ID를 사용해야 하는지 여부는 구현 세부 정보입니다.
  • getExchange() Cryostat - parent exchange 객체에 대한 참조입니다.
  • isFault(), setFault() Cryostat-ECDHEGetter 및 setter 메서드(이 메시지가 오류 메시지인지 여부를 나타내는 오류 플래그) 및 setter 메서드입니다.
  • getHeader(), getHeaders(), setHeaders(), setHeaders(), removeHeader(), hasHeaders(), message headers에 대한Headers() 및 setter 메서드를 포함합니다. 일반적으로 이러한 메시지 헤더는 실제 헤더 데이터를 저장하거나 기타 메타데이터를 저장하는 데 사용할 수 있습니다.
  • getBody(), getMandatoryBody(), setBody() Cryostat- Cryostat-Getter 및 메시지 본문에 대한 setter 메서드. getMandatoryBody() 접근자는 반환된 본문이 null이 아님을 보장합니다. 그렇지 않으면 InvalidPayloadException 예외가 발생합니다.
  • getAttachment(), getAttachments(), getAttachmentNames(), removeAttachment(), addAttachment(), setAttachment() , hasAttachments(), hasAttachments() Cryostat- CryostatMethods to get, set, add, and remove attachments.
  • 현재 사용자 지정 메시지 개체의 동일한 새 복사본 을 만듭니다.Creates a new, identical (including the message ID) copy of the current custom message object.
  • copyFrom() - Cryostat: 지정된 일반 메시지 개체의 전체 콘텐츠(메시지 ID 포함)를 현재 메시지 인스턴스로 복사합니다. 이 메서드는 메시지 유형에서 복사할 수 있어야 하므로 사용자 지정 속성이 아닌 일반 메시지 속성을 복사합니다.Because this method must be able to copy from any message type, it copies the generic message properties, but not the custom properties.
  • 메시지 구현이 ID  제공할 수 있는 경우 이 교환에 대한 고유 ID를 반환하고, 그렇지 않으면 null 을 반환합니다.