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
FieldsModifier and TypeFieldDescriptionprotected booleanprotected static final Stringprotected JdbcCamelCodecprotected static final Stringprotected static final Stringprotected org.springframework.jdbc.core.JdbcTemplateprotected org.springframework.transaction.support.TransactionTemplateprotected org.springframework.transaction.support.TransactionTemplateprotected static final Stringprotected static final StringFields 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
ConstructorsConstructorDescriptionCreates 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.Exchangeadd(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange exchange) org.apache.camel.Exchangeadd(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange) voidbooleanconfirmWithResult(org.apache.camel.CamelContext camelContext, String exchangeId) protected voiddoInit()protected voiddoStart()protected voiddoStop()org.apache.camel.ExchangegetKeys()Returns the keys in the given repositoryorg.springframework.jdbc.support.lob.LobHandlerintintlongbooleanprotected voidinsert(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 intinsertHelper(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange exchange, String sql, Long version) booleanbooleanbooleanbooleanorg.apache.camel.Exchangevoidremove(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange exchange) scan(org.apache.camel.CamelContext camelContext) voidsetAllowSerializedHeaders(boolean allowSerializedHeaders) voidsetDataSource(DataSource dataSource) Sets the DataSource to use for accessing the databasevoidsetDeadLetterUri(String deadLetterUri) An endpoint uri for a Dead Letter Channel where exhausted recovered Exchanges will be moved.voidsetHeadersToStoreAsText(List<String> headersToStoreAsText) Allows to store headers as String which is human readable.voidsetJdbcCamelCodec(JdbcCamelCodec codec) voidsetJdbcOptimisticLockingExceptionMapper(JdbcOptimisticLockingExceptionMapper jdbcOptimisticLockingExceptionMapper) voidsetLobHandler(org.springframework.jdbc.support.lob.LobHandler lobHandler) Sets a custom LobHandler to usevoidsetMaximumRedeliveries(int maximumRedeliveries) voidsetPropagationBehavior(int propagationBehavior) Sets propagation behavior to use with spring transaction templates which are used for database access.voidsetPropagationBehaviorName(String propagationBehaviorName) Sets propagation behavior to use with spring transaction templates which are used for database access.voidsetRecoveryInterval(long interval) voidsetRecoveryInterval(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 voidsetRepositoryName(String repositoryName) Sets the name of the repositoryvoidsetReturnOldExchange(boolean returnOldExchange) Whether the get operation should return the old existing Exchange if any existed.voidsetStoreBodyAsText(boolean storeBodyAsText) Whether to store the message body as String which is human readable.final voidsetTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager) voidsetUseRecovery(boolean useRecovery) Whether or not recovery is enabled.protected voidupdate(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 intupdateHelper(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, suspendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.camel.Service
build, close, init, start, stopMethods inherited from interface org.apache.camel.ShutdownableService
shutdownMethods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods 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:
addin 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:
addin 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:
getin interfaceorg.apache.camel.spi.AggregationRepository
-
remove
public void remove(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange exchange) - Specified by:
removein interfaceorg.apache.camel.spi.AggregationRepository- Specified by:
removein interfaceorg.apache.camel.spi.OptimisticLockingAggregationRepository
-
confirm
- Specified by:
confirmin interfaceorg.apache.camel.spi.AggregationRepository
-
confirmWithResult
- Specified by:
confirmWithResultin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getKeys
- Specified by:
getKeysin interfaceorg.apache.camel.spi.AggregationRepository
-
scan
- Specified by:
scanin 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:
recoverin 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:
setRecoveryIntervalin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setRecoveryInterval
public void setRecoveryInterval(long interval) - Specified by:
setRecoveryIntervalin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getRecoveryIntervalInMillis
public long getRecoveryIntervalInMillis()- Specified by:
getRecoveryIntervalInMillisin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
isUseRecovery
public boolean isUseRecovery()- Specified by:
isUseRecoveryin 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:
setUseRecoveryin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getMaximumRedeliveries
public int getMaximumRedeliveries()- Specified by:
getMaximumRedeliveriesin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setMaximumRedeliveries
public void setMaximumRedeliveries(int maximumRedeliveries) - Specified by:
setMaximumRedeliveriesin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getDeadLetterUri
- Specified by:
getDeadLetterUriin 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:
setDeadLetterUriin 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:
doInitin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doStart
- Overrides:
doStartin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doStop
- Overrides:
doStopin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-