需要从kakfa主题消费,并向quartz2动态提供cron表达式(从kafka主题接收)

vbkedwbf  于 2021-06-04  发布在  Kafka
关注(0)|答案(0)|浏览(194)

问题陈述-我需要使用一个kafka主题,其中我将cron表达式作为头,需要触发quartz并需要动态提供cron表达式。
这是我的代码片段-

from("kafka:{{consumer.topic}}?brokers={{kafka.host}}:{{kafka.port}}......")
    .routeId(routeId)
    //accessing all the header value and then forming a valid cron expression
    .process(new Processor() {
        @Override 
        public void process(Exchange exchange) throws Exception {
            String sec=exchange.getIn().getHeader("second",String.class);
            String min=exchange.getIn().getHeader("minute",String.class);
            String hours=exchange.getIn().getHeader("hours",String.class);       
            body=exchange.getIn().getBody();
            log.info("The original Body : {}",body);
            // Method call to prepare the cron expression based on the headers value
            cronExp=cb.getCronExperssion(sec,min,hours,"?","*","*","*");
            //Setting up the final cron expression to the header    
            exchange.getIn().setHeader("timerObject", timerObj); 
            log.info("The timer object values are: {}", timerObj);
            log.info("The original scheduled time is : {}",startPolicy.getRouteStartTime());
        }
    })
    // because the quartz2 route can’t be at the to side, it should always be a from() that's why i am using the mock:result here, Any better way ???
    .to("mock:result");

// Here I need to give the cron expression which is being stored in the headers.
from("quartz2://group1/trigger1?cron=0/20+*+*+?+*+*+*&stateful=true")
    .routeId(“Scheduler Route”)
    .log(“Scheduler routed started …”)
    .to(“direct:httpRoute”);

我尝试了多种方法,如enrich()、pollenrich,但无法应用cron表达式from headers值。请帮忙。。。。
谢谢迪帕克

暂无答案!

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

相关问题