Class JdbcAggregationRepository
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.processor.aggregate.jdbc.JdbcAggregationRepository
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.AggregationRepository
,org.apache.camel.spi.OptimisticLockingAggregationRepository
,org.apache.camel.spi.RecoverableAggregationRepository
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
- Direct Known Subclasses:
ClusteredJdbcAggregationRepository
,PostgresAggregationRepository
public class JdbcAggregationRepository
extends org.apache.camel.support.service.ServiceSupport
implements org.apache.camel.spi.RecoverableAggregationRepository, org.apache.camel.spi.OptimisticLockingAggregationRepository
JDBC based
AggregationRepository
JdbcAggregationRepository will only preserve any
Serializable compatible data types. If a data type is not such a type its dropped and a WARN is logged. And it only
persists the Message body and the Message headers. The Exchange properties are not persisted.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.camel.spi.OptimisticLockingAggregationRepository
org.apache.camel.spi.OptimisticLockingAggregationRepository.OptimisticLockingException
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected static final String
protected JdbcCamelCodec
protected static final String
protected static final String
protected org.springframework.jdbc.core.JdbcTemplate
protected org.springframework.transaction.support.TransactionTemplate
protected org.springframework.transaction.support.TransactionTemplate
protected static final String
protected static final String
Fields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
-
Constructor Summary
ConstructorDescriptionCreates an aggregation repositoryJdbcAggregationRepository
(org.springframework.transaction.PlatformTransactionManager transactionManager, String repositoryName, DataSource dataSource) Creates an aggregation repository with the three mandatory parameters -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.camel.Exchange
add
(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange exchange) org.apache.camel.Exchange
add
(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange) void
boolean
confirmWithResult
(org.apache.camel.CamelContext camelContext, String exchangeId) protected void
doInit()
protected void
doStart()
protected void
doStop()
org.apache.camel.Exchange
getKeys()
Returns the keys in the given repositoryorg.springframework.jdbc.support.lob.LobHandler
int
int
long
boolean
protected void
insert
(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange exchange, String repositoryName, Long version) Inserts a new record into the given repository table.protected int
insertHelper
(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange exchange, String sql, Long version) boolean
boolean
boolean
boolean
org.apache.camel.Exchange
void
remove
(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange exchange) scan
(org.apache.camel.CamelContext camelContext) void
setAllowSerializedHeaders
(boolean allowSerializedHeaders) void
setDataSource
(DataSource dataSource) Sets the DataSource to use for accessing the databasevoid
setDeadLetterUri
(String deadLetterUri) An endpoint uri for a Dead Letter Channel where exhausted recovered Exchanges will be moved.void
setHeadersToStoreAsText
(List<String> headersToStoreAsText) Allows to store headers as String which is human readable.void
setJdbcCamelCodec
(JdbcCamelCodec codec) void
setJdbcOptimisticLockingExceptionMapper
(JdbcOptimisticLockingExceptionMapper jdbcOptimisticLockingExceptionMapper) void
setLobHandler
(org.springframework.jdbc.support.lob.LobHandler lobHandler) Sets a custom LobHandler to usevoid
setMaximumRedeliveries
(int maximumRedeliveries) void
setPropagationBehavior
(int propagationBehavior) Sets propagation behavior to use with spring transaction templates which are used for database access.void
setPropagationBehaviorName
(String propagationBehaviorName) Sets propagation behavior to use with spring transaction templates which are used for database access.void
setRecoveryInterval
(long interval) void
setRecoveryInterval
(long interval, TimeUnit timeUnit) If recovery is enabled then a background task is run every x'th time to scan for failed exchanges to recover and resubmit.final void
setRepositoryName
(String repositoryName) Sets the name of the repositoryvoid
setReturnOldExchange
(boolean returnOldExchange) Whether the get operation should return the old existing Exchange if any existed.void
setStoreBodyAsText
(boolean storeBodyAsText) Whether to store the message body as String which is human readable.final void
setTransactionManager
(org.springframework.transaction.PlatformTransactionManager transactionManager) void
setUseRecovery
(boolean useRecovery) Whether or not recovery is enabled.protected void
update
(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange exchange, String repositoryName, Long version) Updates the current exchange details in the given repository table.protected int
updateHelper
(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange exchange, String sql, Long version) Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.camel.Service
build, close, init, start, stop
Methods inherited from interface org.apache.camel.ShutdownableService
shutdown
Methods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
Methods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Field Details
-
EXCHANGE
- See Also:
-
ID
- See Also:
-
BODY
- See Also:
-
VERSION
- See Also:
-
VERSION_PROPERTY
- See Also:
-
codec
-
jdbcTemplate
protected org.springframework.jdbc.core.JdbcTemplate jdbcTemplate -
transactionTemplate
protected org.springframework.transaction.support.TransactionTemplate transactionTemplate -
transactionTemplateReadOnly
protected org.springframework.transaction.support.TransactionTemplate transactionTemplateReadOnly -
allowSerializedHeaders
protected boolean allowSerializedHeaders
-
-
Constructor Details
-
JdbcAggregationRepository
public JdbcAggregationRepository()Creates an aggregation repository -
JdbcAggregationRepository
public JdbcAggregationRepository(org.springframework.transaction.PlatformTransactionManager transactionManager, String repositoryName, DataSource dataSource) Creates an aggregation repository with the three mandatory parameters
-
-
Method Details
-
setRepositoryName
Sets the name of the repository -
setTransactionManager
public final void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager) -
setDataSource
Sets the DataSource to use for accessing the database -
add
public org.apache.camel.Exchange add(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange) throws org.apache.camel.spi.OptimisticLockingAggregationRepository.OptimisticLockingException - Specified by:
add
in interfaceorg.apache.camel.spi.OptimisticLockingAggregationRepository
- Throws:
org.apache.camel.spi.OptimisticLockingAggregationRepository.OptimisticLockingException
-
add
public org.apache.camel.Exchange add(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange exchange) - Specified by:
add
in interfaceorg.apache.camel.spi.AggregationRepository
-
update
protected void update(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange exchange, String repositoryName, Long version) throws Exception Updates the current exchange details in the given repository table.- Parameters:
camelContext
- Current CamelContextkey
- Correlation keyexchange
- Aggregated exchangerepositoryName
- Table's nameversion
- Version identifier- Throws:
Exception
-
insert
protected void insert(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange exchange, String repositoryName, Long version) throws Exception Inserts a new record into the given repository table. Note: the exchange properties are NOT persisted.- Parameters:
camelContext
- Current CamelContextcorrelationId
- Correlation keyexchange
- Aggregated exchange to insertrepositoryName
- Table's nameversion
- Version identifier- Throws:
Exception
-
insertHelper
protected int insertHelper(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange exchange, String sql, Long version) throws Exception - Throws:
Exception
-
updateHelper
protected int updateHelper(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange exchange, String sql, Long version) throws Exception - Throws:
Exception
-
get
public org.apache.camel.Exchange get(org.apache.camel.CamelContext camelContext, String correlationId) - Specified by:
get
in interfaceorg.apache.camel.spi.AggregationRepository
-
remove
public void remove(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange exchange) - Specified by:
remove
in interfaceorg.apache.camel.spi.AggregationRepository
- Specified by:
remove
in interfaceorg.apache.camel.spi.OptimisticLockingAggregationRepository
-
confirm
- Specified by:
confirm
in interfaceorg.apache.camel.spi.AggregationRepository
-
confirmWithResult
- Specified by:
confirmWithResult
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getKeys
- Specified by:
getKeys
in interfaceorg.apache.camel.spi.AggregationRepository
-
scan
- Specified by:
scan
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getKeys
Returns the keys in the given repository- Parameters:
repositoryName
- The name of the table- Returns:
- Set of keys in the given repository name
-
recover
public org.apache.camel.Exchange recover(org.apache.camel.CamelContext camelContext, String exchangeId) - Specified by:
recover
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setRecoveryInterval
If recovery is enabled then a background task is run every x'th time to scan for failed exchanges to recover and resubmit. By default this interval is 5000 millis.- Specified by:
setRecoveryInterval
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setRecoveryInterval
public void setRecoveryInterval(long interval) - Specified by:
setRecoveryInterval
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getRecoveryIntervalInMillis
public long getRecoveryIntervalInMillis()- Specified by:
getRecoveryIntervalInMillis
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
isUseRecovery
public boolean isUseRecovery()- Specified by:
isUseRecovery
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setUseRecovery
public void setUseRecovery(boolean useRecovery) Whether or not recovery is enabled. This option is by default true. When enabled the Camel Aggregator automatic recover failed aggregated exchange and have them resubmitted.- Specified by:
setUseRecovery
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getMaximumRedeliveries
public int getMaximumRedeliveries()- Specified by:
getMaximumRedeliveries
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setMaximumRedeliveries
public void setMaximumRedeliveries(int maximumRedeliveries) - Specified by:
setMaximumRedeliveries
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getDeadLetterUri
- Specified by:
getDeadLetterUri
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setDeadLetterUri
An endpoint uri for a Dead Letter Channel where exhausted recovered Exchanges will be moved. If this option is used then the maximumRedeliveries option must also be provided. Important note : if the deadletter route throws an exception, it will be send again to DLQ until it succeed !- Specified by:
setDeadLetterUri
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
isReturnOldExchange
public boolean isReturnOldExchange() -
setReturnOldExchange
public void setReturnOldExchange(boolean returnOldExchange) Whether the get operation should return the old existing Exchange if any existed. By default this option is false to optimize as we do not need the old exchange when aggregating. -
setJdbcCamelCodec
-
hasHeadersToStoreAsText
public boolean hasHeadersToStoreAsText() -
getHeadersToStoreAsText
-
setHeadersToStoreAsText
Allows to store headers as String which is human readable. By default this option is disabled, storing the headers in binary format.- Parameters:
headersToStoreAsText
- the list of headers to store as String
-
isStoreBodyAsText
public boolean isStoreBodyAsText() -
setStoreBodyAsText
public void setStoreBodyAsText(boolean storeBodyAsText) Whether to store the message body as String which is human readable. By default this option is false storing the body in binary format. -
isAllowSerializedHeaders
public boolean isAllowSerializedHeaders() -
setAllowSerializedHeaders
public void setAllowSerializedHeaders(boolean allowSerializedHeaders) -
getPropagationBehavior
public int getPropagationBehavior() -
setPropagationBehavior
public void setPropagationBehavior(int propagationBehavior) Sets propagation behavior to use with spring transaction templates which are used for database access. The default is TransactionDefinition.PROPAGATION_REQUIRED. -
setPropagationBehaviorName
Sets propagation behavior to use with spring transaction templates which are used for database access. The default is TransactionDefinition.PROPAGATION_REQUIRED. This setter accepts names of the constants, like "PROPAGATION_REQUIRED".- Parameters:
propagationBehaviorName
-
-
getLobHandler
public org.springframework.jdbc.support.lob.LobHandler getLobHandler() -
setLobHandler
public void setLobHandler(org.springframework.jdbc.support.lob.LobHandler lobHandler) Sets a custom LobHandler to use -
getJdbcOptimisticLockingExceptionMapper
-
setJdbcOptimisticLockingExceptionMapper
public void setJdbcOptimisticLockingExceptionMapper(JdbcOptimisticLockingExceptionMapper jdbcOptimisticLockingExceptionMapper) -
getRepositoryName
-
getRepositoryNameCompleted
-
doInit
- Overrides:
doInit
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStart
- Overrides:
doStart
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStop
- Overrides:
doStop
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-