为了提高性能,我建议使用带有任务执行器的 executorchannel 来控制线程池大小的数量。这样,当消息到达 jms 队列时,消费者会收到消息并在单独的线程中处理流。请记住,在这种配置中,多线程工作由 taskexecutor 通道执行,taht 将在单独的线程中执行消息的接收,因此您已经很好地考虑了您想要的多线程等级。
对于队列消息通道,确实需要一个轮询器来轮询通道以执行接收,队列容量是幕后原子队列的容量。
你可以在xml中这样配置am executor channel
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:tx="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<tx:executor id="taskExecutor" pool-size="10" queue-capacity="10"/>
<si:channel id="ch" >
<si:dispatcher task-executor="taskExecutor"/>
</si:channel>
</beans>
或以这种方式在 java-dsl
@Bean
public IntegrationFlow storeBookPageByPage(ConnectionFactory connectionFactory,
@Qualifier("createBookQueue") Destination createBookQueue,
@Qualifier("createBookResultQueue") Destination createBookResultQueue,
PdfBookMasterRepository pdfBookMasterRepository,
BookRepository bookRepository){
String tempFilePathBaseDir = environment.getProperty("bookService.storeBookPageByPage.tempFilePathBaseDir");
return IntegrationFlows.from(Jms.messageDriverChannelAdapter(connectionFactory)
.destination(createBookQueue)
.errorChannel(storeBookPageByPageErrorChannel()))
.channel(channels -> channels.executor(Executors.newScheduledThreadPool(5)))
.....
}