org.apache.camel.Message Maven / Gradle / Ivy
/*
* 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,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel;
import java.util.Map;
import java.util.function.Supplier;
import org.apache.camel.spi.HeadersMapFactory;
/**
* Implements the Message pattern and
* represents an inbound or outbound message as part of an {@link Exchange}.
*
* Headers is represented in Camel using a {@link org.apache.camel.util.CaseInsensitiveMap CaseInsensitiveMap}.
* The implementation of the map can be configured by the {@link HeadersMapFactory} which can be set
* on the {@link CamelContext}. The default implementation uses the {@link org.apache.camel.util.CaseInsensitiveMap CaseInsensitiveMap}.
*/
public interface Message {
/**
* Returns the id of the message.
*
* By default the message uses the same id as {@link Exchange#getExchangeId()} as messages are associated with the exchange
* and using different IDs does not offer much value. Another reason is to optimize for performance to avoid generating new IDs.
*
* A few Camel components do provide their own message IDs such as the JMS components.
*
* @return the message id
*/
String getMessageId();
/**
* Sets the id of the message
*
* @param messageId id of the message
*/
void setMessageId(String messageId);
/**
* Returns the exchange this message is related to
*
* @return the exchange
*/
Exchange getExchange();
/**
* Accesses a specific header
*
* @param name name of header
* @return the value of the given header or null if there is no
* header for the given name
*/
Object getHeader(String name);
/**
* Accesses a specific header
*
* @param name name of header
* @param defaultValue the default value to return if header was absent
* @return the value of the given header or defaultValue if there is no
* header for the given name
*/
Object getHeader(String name, Object defaultValue);
/**
* Accesses a specific header
*
* @param name name of header
* @param defaultValueSupplier the default value supplier used to generate the value to return if header was absent
* @return the value of the given header or he value generated by the defaultValueSupplier if there is no
* header for the given name
*/
Object getHeader(String name, Supplier
© 2015 - 2025 Weber Informatics LLC | Privacy Policy