public interface Exchange
Message received by a Consumer.
During processing down the Processor chain, the Exchange provides access to the
current (not the original) request and response Message messages. The Exchange
also holds meta-data during its entire lifetime stored as properties accessible using the
various getProperty(String) methods. The setProperty(String, Object) is
used to store a property. For example you can use this to store security, SLA related
data or any other information deemed useful throughout processing. If an Exchange
failed during routing the Exception that caused the failure is stored and accessible
via the getException() method.
An Exchange is created when a Consumer receives a request. A new Message is
created, the request is set as the body of the Message and depending on the Consumer
other Endpoint and protocol related information is added as headers on the Message.
Then an Exchange is created and the newly created Message is set as the in on the Exchange.
Therefore an Exchange starts its life in a Consumer. The Exchange is then sent down the
Route for processing along a Processor chain. The Processor as the name
suggests is what processes the Message in the Exchange and Camel, in addition to
providing out-of-the-box a large number of useful processors, it also allows you to create your own.
The rule Camel uses is to take the out Message produced by the previous Processor
and set it as the in for the next Processor. If the previous Processor did not
produce an out, then the in of the previous Processor is sent as the next in. At the
end of the processing chain, depending on the Message Exchange Pattern (or MEP)
the last out (or in of no out available) is sent by the Consumer back to the original caller.
Camel, in addition to providing out-of-the-box a large number of useful processors, it also allows
you to implement and use your own. When the Exchange is passed to a Processor, it always
contains an in Message and no out Message. The Processor may produce
an out, depending on the nature of the Processor. The in Message can be accessed
using the getIn() method. Since the out message is null when entering the Processor,
the getOut() method is actually a convenient factory method that will lazily instantiate a
DefaultMessage which you could populate. As an alternative you could
also instantiate your specialized Message and set it on the exchange using the
setOut(org.apache.camel.Message) method. Please note that a Message contains not only
the body but also headers and attachments. If you are creating a new Message the headers and
attachments of the in Message are not automatically copied to the out by Camel and you'll have
to set the headers and attachments you need yourself. If your Processor is not producing a
different Message but only needs to slightly modify the in, you can simply update the in
Message returned by getIn().
See this FAQ entry
for more details.| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ACCEPT_CONTENT_TYPE |
static java.lang.String |
AGGREGATED_COMPLETED_BY |
static java.lang.String |
AGGREGATED_CORRELATION_KEY |
static java.lang.String |
AGGREGATED_SIZE |
static java.lang.String |
AGGREGATED_TIMEOUT |
static java.lang.String |
AGGREGATION_COMPLETE_ALL_GROUPS |
static java.lang.String |
AGGREGATION_COMPLETE_ALL_GROUPS_INCLUSIVE |
static java.lang.String |
AGGREGATION_STRATEGY |
static java.lang.String |
ASYNC_WAIT |
static java.lang.String |
AUTHENTICATION |
static java.lang.String |
AUTHENTICATION_FAILURE_POLICY_ID |
static java.lang.String |
BATCH_COMPLETE |
static java.lang.String |
BATCH_INDEX |
static java.lang.String |
BATCH_SIZE |
static java.lang.String |
BEAN_METHOD_NAME |
static java.lang.String |
BEAN_MULTI_PARAMETER_ARRAY |
static java.lang.String |
BINDING |
static java.lang.String |
BREADCRUMB_ID |
static java.lang.String |
CHARSET_NAME |
static java.lang.String |
CONTENT_ENCODING |
static java.lang.String |
CONTENT_LENGTH |
static java.lang.String |
CONTENT_TYPE |
static java.lang.String |
CORRELATION_ID |
static java.lang.String |
CREATED_TIMESTAMP |
static java.lang.String |
DATASET_INDEX |
static java.lang.String |
DEFAULT_CHARSET_PROPERTY |
static java.lang.String |
DESTINATION_OVERRIDE_URL |
static java.lang.String |
DISABLE_HTTP_STREAM_CACHE |
static java.lang.String |
DUPLICATE_MESSAGE |
static java.lang.String |
ERRORHANDLER_HANDLED |
static java.lang.String |
EVALUATE_EXPRESSION_RESULT |
static java.lang.String |
EXCEPTION_CAUGHT |
static java.lang.String |
EXCEPTION_HANDLED |
static java.lang.String |
EXTERNAL_REDELIVERED |
static java.lang.String |
FAILURE_ENDPOINT |
static java.lang.String |
FAILURE_HANDLED |
static java.lang.String |
FAILURE_ROUTE_ID |
static java.lang.String |
FILE_LAST_MODIFIED |
static java.lang.String |
FILE_LENGTH |
static java.lang.String |
FILE_LOCAL_WORK_PATH |
static java.lang.String |
FILE_LOCK_FILE_ACQUIRED |
static java.lang.String |
FILE_LOCK_FILE_NAME |
static java.lang.String |
FILE_NAME |
static java.lang.String |
FILE_NAME_CONSUMED |
static java.lang.String |
FILE_NAME_ONLY |
static java.lang.String |
FILE_NAME_PRODUCED |
static java.lang.String |
FILE_PARENT |
static java.lang.String |
FILE_PATH |
static java.lang.String |
FILTER_MATCHED |
static java.lang.String |
FILTER_NON_XML_CHARS |
static java.lang.String |
GROUPED_EXCHANGE |
static java.lang.String |
HTTP_BASE_URI |
static java.lang.String |
HTTP_CHARACTER_ENCODING |
static java.lang.String |
HTTP_CHUNKED |
static java.lang.String |
HTTP_METHOD |
static java.lang.String |
HTTP_PATH |
static java.lang.String |
HTTP_PROTOCOL_VERSION |
static java.lang.String |
HTTP_QUERY |
static java.lang.String |
HTTP_RESPONSE_CODE |
static java.lang.String |
HTTP_SERVLET_REQUEST |
static java.lang.String |
HTTP_SERVLET_RESPONSE |
static java.lang.String |
HTTP_URI |
static java.lang.String |
HTTP_URL |
static java.lang.String |
INTERCEPT_SEND_TO_ENDPOINT_WHEN_MATCHED |
static java.lang.String |
INTERCEPTED_ENDPOINT |
static java.lang.String |
LANGUAGE_SCRIPT |
static java.lang.String |
LOG_DEBUG_BODY_MAX_CHARS |
static java.lang.String |
LOG_DEBUG_BODY_STREAMS |
static java.lang.String |
LOOP_INDEX |
static java.lang.String |
LOOP_SIZE |
static java.lang.String |
MAXIMUM_CACHE_POOL_SIZE |
static java.lang.String |
MAXIMUM_ENDPOINT_CACHE_SIZE |
static java.lang.String |
MESSAGE_HISTORY |
static java.lang.String |
MULTICAST_COMPLETE |
static java.lang.String |
MULTICAST_INDEX |
static java.lang.String |
NOTIFY_EVENT |
static java.lang.String |
ON_COMPLETION |
static java.lang.String |
OVERRULE_FILE_NAME |
static java.lang.String |
PARENT_UNIT_OF_WORK |
static java.lang.String |
RECEIVED_TIMESTAMP |
static java.lang.String |
RECIPIENT_LIST_ENDPOINT |
static java.lang.String |
REDELIVERED |
static java.lang.String |
REDELIVERY_COUNTER |
static java.lang.String |
REDELIVERY_DELAY |
static java.lang.String |
REDELIVERY_EXHAUSTED |
static java.lang.String |
REDELIVERY_MAX_COUNTER |
static java.lang.String |
ROLLBACK_ONLY |
static java.lang.String |
ROLLBACK_ONLY_LAST |
static java.lang.String |
ROUTE_STOP |
static java.lang.String |
SKIP_GZIP_ENCODING |
static java.lang.String |
SLIP_ENDPOINT |
static java.lang.String |
SOAP_ACTION |
static java.lang.String |
SPLIT_COMPLETE |
static java.lang.String |
SPLIT_INDEX |
static java.lang.String |
SPLIT_SIZE |
static java.lang.String |
TIMER_COUNTER |
static java.lang.String |
TIMER_FIRED_TIME |
static java.lang.String |
TIMER_NAME |
static java.lang.String |
TIMER_PERIOD |
static java.lang.String |
TIMER_TIME |
static java.lang.String |
TO_ENDPOINT |
static java.lang.String |
TRACE_EVENT |
static java.lang.String |
TRACE_EVENT_EXCHANGE |
static java.lang.String |
TRACE_EVENT_NODE_ID |
static java.lang.String |
TRACE_EVENT_TIMESTAMP |
static java.lang.String |
TRANSFER_ENCODING |
static java.lang.String |
TRY_ROUTE_BLOCK |
static java.lang.String |
UNIT_OF_WORK_EXHAUSTED |
static java.lang.String |
UNIT_OF_WORK_PROCESS_SYNC
Deprecated.
UNIT_OF_WORK_PROCESS_SYNC is not in use and will be removed in future Camel release
|
static java.lang.String |
XSLT_FILE_NAME |
| Modifier and Type | Method and Description |
|---|---|
void |
addOnCompletion(Synchronization onCompletion)
Adds a
Synchronization to be invoked as callback when
this exchange is completed. |
boolean |
containsOnCompletion(Synchronization onCompletion)
Checks if the passed
Synchronization instance is
already contained on this exchange. |
Exchange |
copy()
Creates a copy of the current message exchange so that it can be
forwarded to another destination
|
CamelContext |
getContext()
Returns the container so that a processor can resolve endpoints from URIs
|
java.lang.Exception |
getException()
Returns the exception associated with this exchange
|
<T> T |
getException(java.lang.Class<T> type)
Returns the exception associated with this exchange.
|
java.lang.String |
getExchangeId()
Returns the exchange id (unique)
|
Endpoint |
getFromEndpoint()
Returns the endpoint which originated this message exchange if a consumer on an endpoint
created the message exchange, otherwise this property will be null
|
java.lang.String |
getFromRouteId()
Returns the route id which originated this message exchange if a route consumer on an endpoint
created the message exchange, otherwise this property will be null
|
Message |
getIn()
Returns the inbound request message
|
<T> T |
getIn(java.lang.Class<T> type)
Returns the inbound request message as the given type
|
Message |
getOut()
Returns the outbound message, lazily creating one if one has not already
been associated with this exchange.
|
<T> T |
getOut(java.lang.Class<T> type)
Returns the outbound request message as the given type
Important: If you want to change the current message, then use getIn() instead as it will
ensure headers etc. |
ExchangePattern |
getPattern()
Returns the
ExchangePattern (MEP) of this exchange. |
java.util.Map<java.lang.String,java.lang.Object> |
getProperties()
Returns all of the properties associated with the exchange
|
java.lang.Object |
getProperty(java.lang.String name)
Returns a property associated with this exchange by name
|
<T> T |
getProperty(java.lang.String name,
java.lang.Class<T> type)
Returns a property associated with this exchange by name and specifying
the type required
|
java.lang.Object |
getProperty(java.lang.String name,
java.lang.Object defaultValue)
Returns a property associated with this exchange by name
|
<T> T |
getProperty(java.lang.String name,
java.lang.Object defaultValue,
java.lang.Class<T> type)
Returns a property associated with this exchange by name and specifying
the type required
|
UnitOfWork |
getUnitOfWork()
Returns the unit of work that this exchange belongs to; which may map to
zero, one or more physical transactions
|
java.util.List<Synchronization> |
handoverCompletions()
Handover all the on completions from this exchange
|
void |
handoverCompletions(Exchange target)
Handover all the on completions from this exchange to the target exchange.
|
boolean |
hasOut()
Returns whether an OUT message has been set or not.
|
boolean |
hasProperties()
Returns whether any properties has been set
|
java.lang.Boolean |
isExternalRedelivered()
Returns true if this exchange is an external initiated redelivered message (such as a JMS broker).
|
boolean |
isFailed()
Returns true if this exchange failed due to either an exception or fault
|
boolean |
isRollbackOnly()
Returns true if this exchange is marked for rollback
|
boolean |
isTransacted()
Returns true if this exchange is transacted
|
java.lang.Object |
removeProperty(java.lang.String name)
Removes the given property on the exchange
|
void |
setException(java.lang.Throwable t)
Sets the exception associated with this exchange
Camel will wrap
Throwable into Exception type to
accommodate for the getException() method returning a plain Exception type. |
void |
setExchangeId(java.lang.String id)
Set the exchange id
|
void |
setFromEndpoint(Endpoint fromEndpoint)
Sets the endpoint which originated this message exchange.
|
void |
setFromRouteId(java.lang.String fromRouteId)
Sets the route id which originated this message exchange.
|
void |
setIn(Message in)
Sets the inbound message instance
|
void |
setOut(Message out)
Sets the outbound message
|
void |
setPattern(ExchangePattern pattern)
Allows the
ExchangePattern (MEP) of this exchange to be customized. |
void |
setProperty(java.lang.String name,
java.lang.Object value)
Sets a property on the exchange
|
void |
setUnitOfWork(UnitOfWork unitOfWork)
Sets the unit of work that this exchange belongs to; which may map to
zero, one or more physical transactions
|
static final java.lang.String AUTHENTICATION
static final java.lang.String AUTHENTICATION_FAILURE_POLICY_ID
static final java.lang.String ACCEPT_CONTENT_TYPE
static final java.lang.String AGGREGATED_SIZE
static final java.lang.String AGGREGATED_TIMEOUT
static final java.lang.String AGGREGATED_COMPLETED_BY
static final java.lang.String AGGREGATED_CORRELATION_KEY
static final java.lang.String AGGREGATION_STRATEGY
static final java.lang.String AGGREGATION_COMPLETE_ALL_GROUPS
static final java.lang.String AGGREGATION_COMPLETE_ALL_GROUPS_INCLUSIVE
static final java.lang.String ASYNC_WAIT
static final java.lang.String BATCH_INDEX
static final java.lang.String BATCH_SIZE
static final java.lang.String BATCH_COMPLETE
static final java.lang.String BEAN_METHOD_NAME
static final java.lang.String BEAN_MULTI_PARAMETER_ARRAY
static final java.lang.String BINDING
static final java.lang.String BREADCRUMB_ID
static final java.lang.String CHARSET_NAME
static final java.lang.String CREATED_TIMESTAMP
static final java.lang.String CONTENT_ENCODING
static final java.lang.String CONTENT_LENGTH
static final java.lang.String CONTENT_TYPE
static final java.lang.String CORRELATION_ID
static final java.lang.String DATASET_INDEX
static final java.lang.String DEFAULT_CHARSET_PROPERTY
static final java.lang.String DESTINATION_OVERRIDE_URL
static final java.lang.String DISABLE_HTTP_STREAM_CACHE
static final java.lang.String DUPLICATE_MESSAGE
static final java.lang.String EXCEPTION_CAUGHT
static final java.lang.String EXCEPTION_HANDLED
static final java.lang.String EVALUATE_EXPRESSION_RESULT
static final java.lang.String ERRORHANDLER_HANDLED
static final java.lang.String EXTERNAL_REDELIVERED
static final java.lang.String FAILURE_HANDLED
static final java.lang.String FAILURE_ENDPOINT
static final java.lang.String FAILURE_ROUTE_ID
static final java.lang.String FILTER_NON_XML_CHARS
static final java.lang.String FILE_LOCAL_WORK_PATH
static final java.lang.String FILE_NAME
static final java.lang.String FILE_NAME_ONLY
static final java.lang.String FILE_NAME_PRODUCED
static final java.lang.String FILE_NAME_CONSUMED
static final java.lang.String FILE_PATH
static final java.lang.String FILE_PARENT
static final java.lang.String FILE_LAST_MODIFIED
static final java.lang.String FILE_LENGTH
static final java.lang.String FILTER_MATCHED
static final java.lang.String FILE_LOCK_FILE_ACQUIRED
static final java.lang.String FILE_LOCK_FILE_NAME
static final java.lang.String GROUPED_EXCHANGE
static final java.lang.String HTTP_BASE_URI
static final java.lang.String HTTP_CHARACTER_ENCODING
static final java.lang.String HTTP_METHOD
static final java.lang.String HTTP_PATH
static final java.lang.String HTTP_PROTOCOL_VERSION
static final java.lang.String HTTP_QUERY
static final java.lang.String HTTP_RESPONSE_CODE
static final java.lang.String HTTP_URI
static final java.lang.String HTTP_URL
static final java.lang.String HTTP_CHUNKED
static final java.lang.String HTTP_SERVLET_REQUEST
static final java.lang.String HTTP_SERVLET_RESPONSE
static final java.lang.String INTERCEPTED_ENDPOINT
static final java.lang.String INTERCEPT_SEND_TO_ENDPOINT_WHEN_MATCHED
static final java.lang.String LANGUAGE_SCRIPT
static final java.lang.String LOG_DEBUG_BODY_MAX_CHARS
static final java.lang.String LOG_DEBUG_BODY_STREAMS
static final java.lang.String LOOP_INDEX
static final java.lang.String LOOP_SIZE
static final java.lang.String MAXIMUM_CACHE_POOL_SIZE
static final java.lang.String MAXIMUM_ENDPOINT_CACHE_SIZE
static final java.lang.String MESSAGE_HISTORY
static final java.lang.String MULTICAST_INDEX
static final java.lang.String MULTICAST_COMPLETE
static final java.lang.String NOTIFY_EVENT
static final java.lang.String ON_COMPLETION
static final java.lang.String OVERRULE_FILE_NAME
static final java.lang.String PARENT_UNIT_OF_WORK
static final java.lang.String RECIPIENT_LIST_ENDPOINT
static final java.lang.String RECEIVED_TIMESTAMP
static final java.lang.String REDELIVERED
static final java.lang.String REDELIVERY_COUNTER
static final java.lang.String REDELIVERY_MAX_COUNTER
static final java.lang.String REDELIVERY_EXHAUSTED
static final java.lang.String REDELIVERY_DELAY
static final java.lang.String ROLLBACK_ONLY
static final java.lang.String ROLLBACK_ONLY_LAST
static final java.lang.String ROUTE_STOP
static final java.lang.String SOAP_ACTION
static final java.lang.String SKIP_GZIP_ENCODING
static final java.lang.String SLIP_ENDPOINT
static final java.lang.String SPLIT_INDEX
static final java.lang.String SPLIT_COMPLETE
static final java.lang.String SPLIT_SIZE
static final java.lang.String TIMER_COUNTER
static final java.lang.String TIMER_FIRED_TIME
static final java.lang.String TIMER_NAME
static final java.lang.String TIMER_PERIOD
static final java.lang.String TIMER_TIME
static final java.lang.String TO_ENDPOINT
static final java.lang.String TRACE_EVENT
static final java.lang.String TRACE_EVENT_NODE_ID
static final java.lang.String TRACE_EVENT_TIMESTAMP
static final java.lang.String TRACE_EVENT_EXCHANGE
static final java.lang.String TRY_ROUTE_BLOCK
static final java.lang.String TRANSFER_ENCODING
static final java.lang.String UNIT_OF_WORK_EXHAUSTED
@Deprecated static final java.lang.String UNIT_OF_WORK_PROCESS_SYNC
static final java.lang.String XSLT_FILE_NAME
ExchangePattern getPattern()
ExchangePattern (MEP) of this exchange.void setPattern(ExchangePattern pattern)
ExchangePattern (MEP) of this exchange to be customized.
This typically won't be required as an exchange can be created with a specific MEP
by calling Endpoint.createExchange(ExchangePattern) but it is here just in case
it is needed.pattern - the patternjava.lang.Object getProperty(java.lang.String name)
name - the name of the propertyjava.lang.Object getProperty(java.lang.String name,
java.lang.Object defaultValue)
name - the name of the propertydefaultValue - the default value to return if property was absent<T> T getProperty(java.lang.String name,
java.lang.Class<T> type)
name - the name of the propertytype - the type of the property<T> T getProperty(java.lang.String name,
java.lang.Object defaultValue,
java.lang.Class<T> type)
name - the name of the propertydefaultValue - the default value to return if property was absenttype - the type of the propertyvoid setProperty(java.lang.String name,
java.lang.Object value)
name - of the propertyvalue - to associate with the namejava.lang.Object removeProperty(java.lang.String name)
name - of the propertyjava.util.Map<java.lang.String,java.lang.Object> getProperties()
boolean hasProperties()
Message getIn()
<T> T getIn(java.lang.Class<T> type)
type - the given typevoid setIn(Message in)
in - the inbound messageMessage getOut()
getIn() instead as it will
ensure headers etc. is kept and propagated when routing continues. Bottom line end users should rarely use
this method.
hasOut() method.
See also the class java doc for this Exchange for more details and this
FAQ entry.getIn()<T> T getOut(java.lang.Class<T> type)
getIn() instead as it will
ensure headers etc. is kept and propagated when routing continues. Bottom line end users should rarely use
this method.
hasOut() method.
See also the class java doc for this Exchange for more details and this
FAQ entry.type - the given typegetIn(Class)boolean hasOut()
void setOut(Message out)
out - the outbound messagejava.lang.Exception getException()
<T> T getException(java.lang.Class<T> type)
type - the exception typevoid setException(java.lang.Throwable t)
Throwable into Exception type to
accommodate for the getException() method returning a plain Exception type.t - the caused exceptionboolean isFailed()
getException(),
Message.setFault(boolean),
Message.isFault()boolean isTransacted()
java.lang.Boolean isExternalRedelivered()
boolean isRollbackOnly()
CamelContext getContext()
Exchange copy()
Endpoint getFromEndpoint()
void setFromEndpoint(Endpoint fromEndpoint)
Endpoint implementationsfromEndpoint - the endpoint which is originating this message exchangejava.lang.String getFromRouteId()
void setFromRouteId(java.lang.String fromRouteId)
fromRouteId - the from route idUnitOfWork getUnitOfWork()
void setUnitOfWork(UnitOfWork unitOfWork)
java.lang.String getExchangeId()
void setExchangeId(java.lang.String id)
void addOnCompletion(Synchronization onCompletion)
Synchronization to be invoked as callback when
this exchange is completed.onCompletion - the callback to invoke on completion of this exchangeboolean containsOnCompletion(Synchronization onCompletion)
Synchronization instance is
already contained on this exchange.onCompletion - the callback instance that is being checked forvoid handoverCompletions(Exchange target)
target - the target exchangejava.util.List<Synchronization> handoverCompletions()
Copyright © 2007-2014 Red Hat, Inc.. All Rights Reserved.