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 basedAggregationRepository
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.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
allowSerializedHeaders
protected static String
BODY
protected JdbcCamelCodec
codec
protected static String
EXCHANGE
protected static String
ID
protected org.springframework.jdbc.core.JdbcTemplate
jdbcTemplate
protected org.springframework.transaction.support.TransactionTemplate
transactionTemplate
protected org.springframework.transaction.support.TransactionTemplate
transactionTemplateReadOnly
protected static String
VERSION
protected static String
VERSION_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.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
confirm(org.apache.camel.CamelContext camelContext, String exchangeId)
boolean
confirmWithResult(org.apache.camel.CamelContext camelContext, String exchangeId)
protected void
doInit()
protected void
doStart()
protected void
doStop()
org.apache.camel.Exchange
get(org.apache.camel.CamelContext camelContext, String correlationId)
String
getDeadLetterUri()
List<String>
getHeadersToStoreAsText()
JdbcOptimisticLockingExceptionMapper
getJdbcOptimisticLockingExceptionMapper()
Set<String>
getKeys()
protected Set<String>
getKeys(String repositoryName)
Returns the keys in the given repositoryorg.springframework.jdbc.support.lob.LobHandler
getLobHandler()
int
getMaximumRedeliveries()
int
getPropagationBehavior()
long
getRecoveryIntervalInMillis()
String
getRepositoryName()
String
getRepositoryNameCompleted()
boolean
hasHeadersToStoreAsText()
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
isAllowSerializedHeaders()
boolean
isReturnOldExchange()
boolean
isStoreBodyAsText()
boolean
isUseRecovery()
org.apache.camel.Exchange
recover(org.apache.camel.CamelContext camelContext, String exchangeId)
void
remove(org.apache.camel.CamelContext camelContext, String correlationId, org.apache.camel.Exchange exchange)
Set<String>
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.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.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
-
-
-
-
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:
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
public void confirm(org.apache.camel.CamelContext camelContext, String exchangeId)
- Specified by:
confirm
in interfaceorg.apache.camel.spi.AggregationRepository
-
confirmWithResult
public boolean confirmWithResult(org.apache.camel.CamelContext camelContext, String exchangeId)
- Specified by:
confirmWithResult
in interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getKeys
public Set<String> getKeys()
- Specified by:
getKeys
in interfaceorg.apache.camel.spi.AggregationRepository
-
scan
public Set<String> scan(org.apache.camel.CamelContext camelContext)
- Specified by:
scan
in 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:
recover
in 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:
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
public String getDeadLetterUri()
- Specified by:
getDeadLetterUri
in 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:
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
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()
-
doInit
protected void doInit() throws Exception
- Overrides:
doInit
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStart
protected void doStart() throws Exception
- Overrides:
doStart
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
-