Class CamelMessageHandler

All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Ordered, ExpressionCapable, Orderable, MessageProducer, HeaderPropagationAware, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>

public class CamelMessageHandler extends AbstractReplyProducingMessageHandler
A MessageHandler for calling Apache Camel route and produce (optionally) a reply.

In the async mode, the ProducerTemplate.asyncSend(Endpoint, Exchange) is used.

The request-reply behavior can be controlled via ExchangePattern configuration or per message. By default, this handler works in an ExchangePattern.InOnly mode.

A default "mapping all headers" between Spring Integration and Apache Camel messages behavior can be customized via setHeaderMapper(HeaderMapper) option.

The target Apache Camel endpoint to call can be determined by the endpointUriExpression. By default, a ProducerTemplate.getDefaultEndpoint() is used.

Artem Bilan
See Also:
  • Constructor Details

    • CamelMessageHandler

      public CamelMessageHandler()
    • CamelMessageHandler

      public CamelMessageHandler(org.apache.camel.ProducerTemplate producerTemplate)
  • Method Details

    • setEndpointUri

      public void setEndpointUri(String endpointUri)
      Set Camel route endpoint uri to send a message. Mutually exclusive with setEndpointUriExpression(Expression) and setRoute(LambdaRouteBuilder).
      endpointUri - the Camel route endpoint to send a message.
    • setEndpointUriExpression

      public void setEndpointUriExpression(Expression endpointUriExpression)
      Set Camel route endpoint uri to send a message. Mutually exclusive with setEndpointUri(String) and setRoute(LambdaRouteBuilder).
      endpointUriExpression - the SpEL expression to determine a Camel route endpoint to send a message.
    • setRoute

      public void setRoute(org.apache.camel.builder.LambdaRouteBuilder route)
      Set a LambdaRouteBuilder to add an inline Camel route definition. Can be used as a lambda rb -> rb.from("direct:inbound").bean(MyBean.class) or reference to external instance. Mutually exclusive with setEndpointUri(String) and setEndpointUriExpression(Expression). The endpoint to send a message is extracted from the target RouteBuilder.
      route - the LambdaRouteBuilder to use.
    • setExchangePattern

      public void setExchangePattern(org.apache.camel.ExchangePattern exchangePattern)
    • setExchangePatternExpression

      public void setExchangePatternExpression(Expression exchangePatternExpression)
    • setHeaderMapper

      public void setHeaderMapper(HeaderMapper<org.apache.camel.Message> headerMapper)
      Set a HeaderMapper to map request message headers into Apache Camel message headers and back if request-reply exchange pattern is used.
      headerMapper - the HeaderMapper to use.
    • setExchangeProperties

      public void setExchangeProperties(Map<String,Object> exchangeProperties)
    • setExchangePropertiesExpression

      public void setExchangePropertiesExpression(Expression exchangePropertiesExpression)
      Set a SpEL expression to evaluate Exchange properties as a Map.
      exchangePropertiesExpression - the expression for exchange properties.
    • doInit

      protected final void doInit()
      doInit in class AbstractReplyProducingMessageHandler
    • handleRequestMessage

      protected Object handleRequestMessage(Message<?> requestMessage)
      Description copied from class: AbstractReplyProducingMessageHandler
      Subclasses must implement this method to handle the request Message. The return value may be a Message, a MessageBuilder, or any plain Object. The base class will handle the final creation of a reply Message from any of those starting points. If the return value is null, the Message flow will end here.
      Specified by:
      handleRequestMessage in class AbstractReplyProducingMessageHandler
      requestMessage - The request message.
      The result of handling the message, or null.