java—尝试使用rabbitmq为spring批处理创建主项目和从项目工作没人接

hi3rlvi2  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(200)

我从这个链接引用https://www.youtube.com/watch?v=j6iplfm7n6w. 主服务和辅助服务都已启动,但未触发作业。它并没有把任何信息从主人传给工人。我附加了带有partitioner和rabbitmq入站和出站配置的主配置代码。
我还需要知道是否有任何设置,我需要做的 application.yml 文件。

@Slf4j
    @Profile("master")
    @Configuration
    public class MasterConfigurations {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private RemotePartitioningMasterStepBuilderFactory managerStepBuilderFactory;

    @Bean
    public Job remotePartitioningJob() {
        return this.jobBuilderFactory.get("remotePartitioningJob").start(masterStep()).build();
    }

    @Bean
    public DirectChannel requests() {
        return new DirectChannel();
    }

    @Bean
    public IntegrationFlow outboundFlow(AmqpTemplate amqpTemplate) {
        return IntegrationFlows.from(requests()).handle(Amqp.outboundAdapter(amqpTemplate).routingKey("requests"))
                .get();
    }

    /*
     * Configure inbound flow (replies coming from workers)
     */
    @Bean
    public DirectChannel replies() {
        return new DirectChannel();
    }

    @Bean
    public IntegrationFlow inboundFlow(ConnectionFactory connectionFactory) {
        return IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, "replies")).channel(replies()).get();
    }

    @Bean
    @StepScope
    public MultiResourcePartitioner partitioner(
            @Value("#{jobParameters['inputFiles']}") Resource[] resources) {
        MultiResourcePartitioner partitioner = new MultiResourcePartitioner();
        partitioner.setKeyName("file");
        partitioner.setResources(resources);
        return partitioner;
    }

    @Bean
    public Step masterStep() {
        log.info("Inside masterStep()");
        return this.managerStepBuilderFactory.get("masterStep").partitioner("workerStep", partitioner(null))
                .outputChannel(requests()).inputChannel(replies()).build();
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题