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

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

问题描述

我在 Camel 上下文中有多个路由和多个端点.所以需要得到一个Route创建的所有端点:

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/outbox2.mock://someway3.http://website.com/file.txt4.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 的 Route 中获取 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天全站免登陆