我正在设置一个 Spring 集成配置以使用多线程从 redis 读取,但是当我运行我的应用程序时,Spring 只创建一个线程。
我正在创建一个 int-redis:queue-inbound-channel-adapter,其中包含一个池大小 = 500 且队列容量 = 0 的执行器任务。
<redis:queue-inbound-channel-adapter
id="fromRedis" channel="privateAggregationExecutorChannel" queue="${instance}_private"
receive-timeout="1000" recovery-interval="3000" expect-message="false" error-channel="distributionErrors"
auto-startup="false" task-executor="robotTaskExecutor"/>
<task:executor
id="robotTaskExecutor"
pool-size="500"
queue-capacity="0"
keep-alive="50"
rejection-policy="CALLER_RUNS" />
<int:service-activator input-channel="privateAggregationExecutorChannel" ref="aggregationExecutor" method="run" />
我不知道我做错了什么,或者我是否缺少了什么。我感谢您的帮助。
错。RedisQueueMessageDrivenEndpoint
实际上是单线程组件:
@Override
protected void doStart() {
if (!this.active) {
this.active = true;
this.restart();
}
}
private void restart() {
this.taskExecutor.execute(new ListenerTask());
}
如您所见,仅从此通道适配器计划了一个ListenerTask
。
要使其多线程,最好有一个ExecutorChannel
从此通道适配器发送消息。这样,即使RedisQueueMessageDrivenEndpoint
是单线程的,您仍将拥有多线程处理。
我们刚刚意识到,当我们可以解决其他简单方法时,将并发引入此组件会有点复杂。
另一种方法是为要发送的同一queue
和same
通道设置多个<redis:queue-inbound-channel-adapter>
定义。