【发布时间】:2022-01-17 05:59:12
【问题描述】:
我是 Spring 集成和批处理的新手,我想开发一个带有 master 和 worker 的远程分块批处理应用程序。我使用 spring 集成和 RabbitMQ 作为消息队列,应用程序运行良好但 worker itemProccessor 自动启动,但是我需要控制何时启动它。
@Configuration
@EnableBatchProcessing
@EnableBatchIntegration
@EnableIntegration
public class WorkerConfig {
@Autowired
private RemoteChunkingWorkerBuilder<Integer, Integer> remoteChunkingWorkerBuilder;
@Bean
public DirectChannel requestsChannel() {
return new DirectChannel();
}
@Bean
public IntegrationFlow inboundFlow(ConnectionFactory connectionFactory) {
return IntegrationFlows
.from(Amqp.inboundAdapter(connectionFactory,"requests"))
.channel(requestsChannel())
.get();
}
@Bean
public DirectChannel repliesChannel() {
System.out.println("repliesChannel 3 ");
return new DirectChannel();
}
@Bean
public IntegrationFlow outboundFlow(AmqpTemplate amqpTemplate) {
return IntegrationFlows
.from(repliesChannel())
.handle(Amqp.outboundAdapter(amqpTemplate).routingKey("replies"))
.get();
}
@Bean
public ItemProcessor<Integer, Integer> itemProcessor() {
....
}
@Bean
public ItemWriter<Integer> itemWriter() {
...
}
@Bean
public IntegrationFlow workerIntegrationFlow() {
return this.remoteChunkingWorkerBuilder
.itemProcessor(itemProcessor())
.itemWriter(itemWriter())
.inputChannel(requestsChannel())
.outputChannel(repliesChannel())
.build();
}
}
那么我可以做些什么来手动启动工人部分?
【问题讨论】:
标签: spring spring-boot rabbitmq spring-batch spring-integration