问题描述
我的阿帕奇骆驼路线:
<from uri="jms:letsgo?concurrentConsumers=10"/>
<aggregate strategyRef="timeoutAwareAggregationStrategy" aggregationRepositoryRef="jdbcAggregationRepository" optimisticLocking="true"
discardOnCompletionTimeout="false" completionSize="2">
<correlationExpression>
<header>AckNowledgeMsgiD</header>
</correlationExpression>
<to uri="direct-vm:test/>
</aggregate>
我使用aggregationRepositoryRef 和org.apache.camel.processor.aggregate.jdbc.JdbcAggregationRepository
使用 optimisticLocking="true" 我看到 x2 速度性能,但与数据库的对话相同,意味着 apache camel core 内部发生了一些事情,但是什么?
在 2.X 的文档中不包含列 version https://camel.apache.org/components/2.x/sql-component.html#_database
apache 骆驼 2.23,postgresql 9.6
UPD:
我找到了类AggregateProcessor,其中有一个条件(省略了一些代码行)
if (optimisticLocking){
do {
try {
aggregated = doAggregation(key,copy);
exhaustedRetries = false;
break;
} catch (OptimisticLockingAggregationRepository.OptimisticLockingException e) {
LOG.trace("On attempt {} OptimisticLockingAggregationRepository: {} threw OptimisticLockingException while trying to add() key: {} and exchange: {}",new Object[]{attempt,aggregationRepository,key,copy,e});
optimisticLockRetryPolicy.doDelay(attempt);
}
} while (optimisticLockRetryPolicy.shouldRetry(attempt));
}else{
lock.lock();
try {
aggregated = doAggregation(key,copy);
} finally {
lock.unlock();
}}
如果您查看方法 doAggregation(key,copy) 的文档:
This method must be run synchronized as we cannot aggregate the same correlation key in parallel.
在我的例子中,我们从多个线程(concurrentConsumers=10)进入该方法
while (optimisticLockRetryPolicy.shouldRetry(attempt))
默认时间 RetryPolicy( private long retryDelay = 50L;)
假设我有所有不同的关联键,那么如果锁被禁用,我仍然会在一个线程中处理它们吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)