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.OptimisticLockingAggregationRepositoryJDBC basedAggregationRepositoryJdbcAggregationRepository 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanallowSerializedHeadersprotected static StringBODYprotected JdbcCamelCodeccodecprotected static StringEXCHANGEprotected static StringIDprotected org.springframework.jdbc.core.JdbcTemplatejdbcTemplateprotected org.springframework.transaction.support.TransactionTemplatetransactionTemplateprotected org.springframework.transaction.support.TransactionTemplatetransactionTemplateReadOnlyprotected static StringVERSIONprotected static StringVERSION_PROPERTY
-
Constructor Summary
Constructors Constructor Description JdbcAggregationRepository()Creates an aggregation repositoryJdbcAggregationRepository(org.springframework.transaction.PlatformTransactionManager transactionManager, String repositoryName, DataSource dataSource)Creates an aggregation repository with the three mandatory parameters
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.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)voidconfirm(org.apache.camel.CamelContext camelContext, String exchangeId)booleanconfirmWithResult(org.apache.camel.CamelContext camelContext, String exchangeId)protected voiddoInit()protected voiddoStart()protected voiddoStop()org.apache.camel.Exchangeget(org.apache.camel.CamelContext camelContext, String correlationId)StringgetDeadLetterUri()StringgetDeserializationFilter()List<String>getHeadersToStoreAsText()JdbcOptimisticLockingExceptionMappergetJdbcOptimisticLockingExceptionMapper()Set<String>getKeys()protected Set<String>getKeys(String repositoryName)Returns the keys in the given repositoryorg.springframework.jdbc.support.lob.LobHandlergetLobHandler()intgetMaximumRedeliveries()intgetPropagationBehavior()longgetRecoveryIntervalInMillis()StringgetRepositoryName()StringgetRepositoryNameCompleted()booleanhasHeadersToStoreAsText()protected 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)booleanisAllowSerializedHeaders()booleanisReturnOldExchange()booleanisStoreBodyAsText()booleanisUseRecovery()org.apache.camel.Exchangerecover(org.apache.camel.CamelContext camelContext, String exchangeId)voidremove(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange exchange)Set<String>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.voidsetDeserializationFilter(String deserializationFilter)Sets a deserialization filter while reading Object from Aggregation Repository.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.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.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, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Field Detail
-
EXCHANGE
protected static final String EXCHANGE
- See Also:
- Constant Field Values
-
ID
protected static final String ID
- See Also:
- Constant Field Values
-
BODY
protected static final String BODY
- See Also:
- Constant Field Values
-
VERSION
protected static final String VERSION
- See Also:
- Constant Field Values
-
VERSION_PROPERTY
protected static final String VERSION_PROPERTY
- See Also:
- Constant Field Values
-
codec
protected JdbcCamelCodec 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 Detail
-
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 Detail
-
setRepositoryName
public final void setRepositoryName(String repositoryName)
Sets the name of the repository
-
setTransactionManager
public final void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
-
setDataSource
public void setDataSource(DataSource dataSource)
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 ExceptionUpdates 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 ExceptionInserts 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
public void confirm(org.apache.camel.CamelContext camelContext, String exchangeId)- Specified by:
confirmin interfaceorg.apache.camel.spi.AggregationRepository
-
confirmWithResult
public boolean confirmWithResult(org.apache.camel.CamelContext camelContext, String exchangeId)- Specified by:
confirmWithResultin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getKeys
public Set<String> getKeys()
- Specified by:
getKeysin interfaceorg.apache.camel.spi.AggregationRepository
-
scan
public Set<String> scan(org.apache.camel.CamelContext camelContext)
- Specified by:
scanin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getKeys
protected Set<String> getKeys(String repositoryName)
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
public 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. 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
public String getDeadLetterUri()
- Specified by:
getDeadLetterUriin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setDeadLetterUri
public void setDeadLetterUri(String deadLetterUri)
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
public void setJdbcCamelCodec(JdbcCamelCodec codec)
-
hasHeadersToStoreAsText
public boolean hasHeadersToStoreAsText()
-
setHeadersToStoreAsText
public void setHeadersToStoreAsText(List<String> headersToStoreAsText)
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
public void setPropagationBehaviorName(String propagationBehaviorName)
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
public JdbcOptimisticLockingExceptionMapper getJdbcOptimisticLockingExceptionMapper()
-
setJdbcOptimisticLockingExceptionMapper
public void setJdbcOptimisticLockingExceptionMapper(JdbcOptimisticLockingExceptionMapper jdbcOptimisticLockingExceptionMapper)
-
getRepositoryName
public String getRepositoryName()
-
getRepositoryNameCompleted
public String getRepositoryNameCompleted()
-
getDeserializationFilter
public String getDeserializationFilter()
-
setDeserializationFilter
public void setDeserializationFilter(String deserializationFilter)
Sets a deserialization filter while reading Object from Aggregation Repository. By default the filter will allow all java packages and subpackages and all org.apache.camel packages and subpackages, while the remaining will be blacklisted and not deserialized. This parameter should be customized if you're using classes you trust to be deserialized.
-
doInit
protected void doInit() throws Exception- Overrides:
doInitin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doStart
protected void doStart() throws Exception- Overrides:
doStartin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
-