Interface ExchangeFactory

All Superinterfaces:
AutoCloseable, CamelContextAware, HasCamelContext, NonManagedService, PooledObjectFactory<Exchange>, RouteIdAware, Service

public interface ExchangeFactory extends PooledObjectFactory<Exchange>, NonManagedService, RouteIdAware
Factory used by Consumer (and PollingConsumer) to create the Exchange that carries an incoming message into Camel.

This factory governs only the exchanges that enter Camel from the outside world via a consumer. Sub-exchanges created internally (e.g., by the Splitter EIP) are outside this contract and use ProcessorExchangeFactory instead.

The factory is pluggable to support two exchange-lifecycle strategies:

  • default — allocates a fresh Exchange for every inbound message; simple and GC-friendly for low-volume routes.
  • pooled — reuses PooledExchange instances from an object pool; reduces garbage-collection pressure on high-throughput routes by recycling the exchange and its internal state after each routing cycle completes.
Camel selects the strategy at startup based on the exchangeFactory configuration option on the CamelContext.
Since:
3.9
See Also:
  • Field Details

  • Method Details

    • getConsumer

      @Nullable Consumer getConsumer()
      The consumer using this factory.
    • newExchangeFactory

      ExchangeFactory newExchangeFactory(Consumer consumer)
      Creates a new ExchangeFactory that is private for the given consumer.
      Parameters:
      consumer - the consumer that will use the created ExchangeFactory
      Returns:
      the created factory.
    • create

      Exchange create(boolean autoRelease)
      Gets a new Exchange
      Parameters:
      autoRelease - whether to auto release the exchange when routing is complete via UnitOfWork
    • create

      Exchange create(Endpoint fromEndpoint, boolean autoRelease)
      Gets a new Exchange
      Parameters:
      fromEndpoint - the from endpoint
      autoRelease - whether to auto release the exchange when routing is complete via UnitOfWork
    • release

      default boolean release(Exchange exchange)
      Releases the exchange back into the pool
      Specified by:
      release in interface PooledObjectFactory<Exchange>
      Parameters:
      exchange - the exchange
      Returns:
      true if released into the pool, or false if something went wrong and the exchange was discarded