即使我使用ExecutorService也无法启动骆驼并行处理

时间:2020-08-07 09:22:08

标签: java multithreading apache-camel executorservice spring-camel

我想在并行执行的程序中创建2种处理方式。 目前,我正在使用骆驼线程来处理文件,并且可以正常工作,但是与此同时,我想运行消耗卡夫卡消息的程序。 2可以独立工作,但不能并行。 这是我的代码:

FileRouteBuilder:

@Component
public class FileRouteBuilder extends SpringRouteBuilder {


    private KafkaListener KafkaListener;
    
    private WorkflowEventConsumerRoute workflowEventConsumerRoute;
    
    private CamelContext camelContext;
    
    @Autowired 
    public FileRouteBuilder(final KafkaListener KafkaListener,CamelContext camelContext) {
        this.KafkaListener = KafkaListener;
        this.camelContext=camelContext;

        ExecutorService exec = Executors.newFixedThreadPool(25);
        exec.execute(new Runnable() {
            @Override
            public void run() {
                while(true){
                    KafkaListener.processMessage();
                }
            }
        });
        exec.shutdown();
    }
    

    @Override
    public void configure() throws Exception {

        //while(true){
        final String filePathIn = "/location"
        final String schemaPath = "**.xsd";

        final DataFormat jacksonDataFormat = new JacksonXMLDataFormat(RequestDto.class);
        
        from("file:" ******)
                // process ok
                .end();
        //}
    }
    

}

KafkaListener:

@Component
public class KafkaListener /*implements Runnable */{


    @Value("${kafka.topic}")
    private transient String topic;
    
    @Autowired
    @Qualifier("consumerConfig")
    private transient Properties kafkaConfig;
    
    KafkaConsumer<Long, GenericRecord> consumer;
    
    
    public void processMessage()  {
    
        LOGGER.debug("---------- Process consumer-----------");
        consumer = new KafkaConsumer<>(kafkaConfig);
            
        consumer.subscribe(Collections.singletonList(topic));
            while (true) {
                //process
            }
    }
}

我尝试创建2条from(),然后创建2条骆驼路线,但没有成功。 你能帮我吗?

0 个答案:

没有答案
相关问题