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
Exchangefor every inbound message; simple and GC-friendly for low-volume routes. - pooled — reuses
PooledExchangeinstances 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.
exchangeFactory configuration option on the
CamelContext.- Since:
- 3.9
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface PooledObjectFactory
PooledObjectFactory.Statistics -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptioncreate(boolean autoRelease) Gets a newExchangeGets a newExchange@Nullable ConsumerThe consumer using this factory.newExchangeFactory(Consumer consumer) Creates a newExchangeFactorythat is private for the given consumer.default booleanReleases the exchange back into the poolMethods inherited from interface CamelContextAware
setCamelContextMethods inherited from interface HasCamelContext
getCamelContextMethods inherited from interface PooledObjectFactory
acquire, getCapacity, getSize, getStatistics, isPooled, isStatisticsEnabled, purge, resetStatistics, setCapacity, setStatisticsEnabledMethods inherited from interface RouteIdAware
getRouteId, setRouteId
-
Field Details
-
FACTORY
-
-
Method Details
-
getConsumer
@Nullable Consumer getConsumer()The consumer using this factory. -
newExchangeFactory
Creates a newExchangeFactorythat is private for the given consumer.- Parameters:
consumer- the consumer that will use the createdExchangeFactory- Returns:
- the created factory.
-
create
Gets a newExchange- Parameters:
autoRelease- whether to auto release the exchange when routing is complete viaUnitOfWork
-
create
Gets a newExchange- Parameters:
fromEndpoint- the from endpointautoRelease- whether to auto release the exchange when routing is complete viaUnitOfWork
-
release
Releases the exchange back into the pool- Specified by:
releasein interfacePooledObjectFactory<Exchange>- Parameters:
exchange- the exchange- Returns:
- true if released into the pool, or false if something went wrong and the exchange was discarded
-