如何查找路由的所有端点(Apache Camel,Java) [英] How to find all Endpoints of route (Apache Camel, Java)

查看:257
本文介绍了如何查找路由的所有端点(Apache Camel,Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在骆驼语境中,我有数条路线和许多终点.因此需要获取由一个路由创建的所有端点:

I have several routes and many endpoints in Camel context. So need to get all endpoints created by one Route:

    CamelContext context = new DefaultCamelContext();
    RouteBuilder route1 = new RouteBuilder() {
        public void configure() {
            from("file:data/inbox?noop=true")
                    .routeId("myRoute1")
                    .enrich("http://website.com/file.txt")
                    .to("file:data/outbox")
                    .to("mock:someway");
        }
    };

    RouteBuilder route2 = new RouteBuilder() {
        public void configure() {
            from("file:data/outbox?noop=true")
                    .routeId("myRoute2")
                    .to("mock:myMom");
        }
    };

    context.addRoutes(route1);
    context.addRoutes(route2);

    context.start();

    // TODO 

    context.stop();

在停止之前,我需要获取所有由myRoute1创建的终结点?例如:

And before stop I need get all endpoints which created by myRoute1 ??? for example:

1.file://data/outbox 2.模拟://someway 3. http://website.com/file.txt 4.file://data/inbox?noop = true

1.file://data/outbox 2.mock://someway 3.http://website.com/file.txt 4.file://data/inbox?noop=true

我只能将骆驼上下文的所有端点获取为:context.getEndpoints()

I can get only all Endpoints of Camel context as: context.getEndpoints()

推荐答案

您可以尝试以下操作:

  1. 为您的路线指定一个routeId,以便以后对其进行识别.
  2. 从CamelContext的路由中获取RouteDefinition,并过滤ToDefinition对象的输出列表.

  1. Give your route an routeId to be able to identify it later.
  2. Get the RouteDefinition from the Route from the CamelContext and filter the List of Outputs for the ToDefinition objects.

 List<ProcessorDefinition> outputProcessorDefs = exchange.getContext().getRouteDefinition("[routeId]").getOutputs();
 // Iterate and get all ProcessorDefinition objects which inherit from the ToDefinition

这篇关于如何查找路由的所有端点(Apache Camel,Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆