【问题标题】:Shutdown Spring Application after camel route has sent data骆驼路由发送数据后关闭Spring应用程序
【发布时间】:2021-06-19 23:37:24
【问题描述】:

我在 Spring 应用程序中使用 Camel。我需要的是在骆驼发送所有数据后正确关闭我的应用程序。基本上骆驼必须读取一个文件,将其分成几行并将每一行作为卡夫卡按摩发送。 骆驼完成发送所有消息后如何关闭我的应用程序? 这是我的路线:

public class Router extends RouteBuilder {

@Override
public void configure() throws Exception {

    // Kafka Producer
    from("file:{{file.dir}}?fileName={{file.name}}&noop=true")
            .split(body().tokenize("\r\n|\n")).streaming()
            .to("kafka:{{kafka.topic}}?brokers={{spring.kafka.producer.bootstrap-servers}}");
}
}

【问题讨论】:

  • 一个onCompletion 回调可以关闭Spring ApplicationContext。

标签: java spring-boot apache-kafka apache-camel


【解决方案1】:

基本上你可以调用 System.exit 命令

 from("file:{{file.dir}}?fileName={{file.name}}&noop=true").routeId("fileconsumer")
            .split(body().tokenize("\r\n|\n")).streaming()
            .to("kafka:{{kafka.topic}}?brokers={{spring.kafka.producer.bootstrap-servers}}")
            .process(exchange -> System.exit(0));

或者你可以停止骆驼路线

CamelContext context = exchange.getContext();
      context.stopRoute("fileconsumer");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-04
    • 2015-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-25
    相关资源
    最近更新 更多