template 使用参考链接

Java Code Examples fororg.apache.camel.ProducerTemplate

Introduction to the Producer Template

1在代码中如何获取 camleContext 原文链接

CamelContextAware If you want to be injected with the CamelContext in your POJO just implement the CamelContextAware interface; then when Spring creates your POJO the CamelContext will be injected into your POJO. Also see the Bean Integration for further injections.

You can create a bean in Spring that implements CamelContextAware, something like this:

import org.springframework.stereotype.Service;
@Servicepublic class RouteManager implements CamelContextAware { protected static CamelContext camelContext;public CamelContext getCamelContext() {return camelContext;}public void setCamelContext(CamelContext camelContext) {this.camelContext = camelContext;}
}

If you don't use the annotation you can use:

<bean id="RouteManager " class="myPackage.RouteManager" />

2,在代码中加载 route.xml   原文链接

Loading routes from XML files

Available as of Camel 2.6

This cookbook shows how to load and add routes from XML files into an existing CamelContext.

When adding routes as shown on this page, the routes is isolated and cannot re-use any existing onExceptionintercept etc.

You can define Camel routes in XML files using the <routes> tag with the namespace "http://camel.apache.org/schema/spring".
Suppose we have the bar route as shown below in the barRoute.xml XML file.

barRoute.xml
<routesxmlns="http://camel.apache.org/schema/spring">
    <!-- here we define the bar route -->
    <routeid="bar">
        <fromuri="direct:bar"/>
        <touri="mock:bar"/>
    </route>
    <!-- we could add more routes if we like,
         but in this example we stick to one route only -->
</routes>

We can then load this route and add to the existing CamelContext using the following lines of code:

Java code
// load route from XML and add them to the existing camel context
InputStream is = getClass().getResourceAsStream("barRoute.xml");
RoutesDefinition routes = context.loadRoutesDefinition(is);
context.addRouteDefinitions(routes.getRoutes());

If you are using older versions of Camel, you can do this as well but it requires a bit more work. See this commit log.

Adding Routes dynamically

@Component 
public class RssRouter implements CamelContextAware {

protected CamelContext camelContext; 
    RssRouteBuilder rssRouteBuilder;

final Logger log = Logger.getLogger(this.getClass());

public void addFeed(String uri) throws Exception { 
        log.info("Adding feed '" + uri + "'"); 
        uri = "rss://" + uri;

camelContext.addRouteDefinition(rssRouteBuilder.getRouteDefinition(uri)); 
    }

public void removeFeed(String uri) throws Exception { 
        log.info("Removing feed '" + uri + "'"); 
        uri = "rss://" + uri; 
        camelContext.removeRoute(uri); 
    }

public CamelContext getCamelContext() { 
        return camelContext; 
    }

public void setCamelContext(CamelContext camelContext) { 
        this.camelContext = camelContext; 
    }

public void setRssRouteBuilder(RssRouteBuilder rssRouteBuilder) { 
        this.rssRouteBuilder = rssRouteBuilder; 
    }

}

public class RssRouteBuilder extends RouteBuilder {

@Override 
    public void configure() throws Exception { 
// Do nothing here since we are creating routes dynamically 
    }

RouteDefinition getRouteDefinition(String uri) { 
      return  from(uri + "?splitEntries=false&consumer.initialDelay=0"). 
                marshal().rss(). 
                to("mock:result").routeId("routeId"); 
    }

}

apache camle template , Adding Routes dynamically相关推荐

  1. Professional C# 6 and .NET Core 1.0 - Chapter 41 ASP.NET MVC

    What's In This Chapter? Features of ASP.NET MVC 6 Routing Creating Controllers Creating Views Valida ...

  2. react入门代码_如何在React中构建温度控制应用程序-包括提示和入门代码

    react入门代码 我们正在建立的 (What we're building) In this beginner React project, we're going to learn how to ...

  3. 极路由添加静态路由表_如何将静态TCP / IP路由添加到Windows路由表

    极路由添加静态路由表 In some specific types of environments, you might find it useful to add a static route to ...

  4. rails 创建_使用Rails和Icecast创建在线流媒体广播

    rails 创建 Hello and welcome to this article! Today I would like to talk about creating an online stre ...

  5. 使用ES6,Pt更好JavaScript。 III:酷收藏和闪烁的弦

    介绍 ( Introduction ) ES2015 brings some heavy-hitting changes to the language, such as promises and g ...

  6. java camel exchange类_Exchange服务器之camel 基本概念

    本文将带你了解Exchange服务器之camel 基本概念,希望本文对大家学Exchange有所帮助. camel 对exchange的几种处理consuming方式: 1. bean 2. bean ...

  7. 基于Allatori7.6的Java代码混淆

    基于Allatori7.6对Java代码实现代码混淆 第一步:下载Allatori7.6 http://www.allatori.com/ 第二步:解压Allatori-7.6-Demo.zip 解压 ...

  8. 模仿Hibernate的逆向工程_java版_源码下载

    在这篇blog:"Hibernate逆向工程原理_java版本"中谈到了Hibernate逆向工程原理. 我喜欢理论和实践相结合....so,今天我试着模仿hibernate的逆向 ...

  9. 模板引擎:VelocityFreeMarker(转)

    Velocity,名称字面翻译为:速度.速率.迅速,用在Web开发里,用过的人可能不多,大都基本知道和在使用Struts,到底Velocity和Struts(Taglib和Tiles)是如何联系?在技 ...

最新文章

  1. vue中的axios封装
  2. phpstorm中的快捷键
  3. android布局加色,android – 如何以编程方式将LinearLayout添加背景颜色,并将权重添加到另一个布局...
  4. 深入理解final关键字
  5. POJ - 1226 Substrings(后缀数组+二分)
  6. Oracle中实现continue的方法
  7. 思科IPS系统的bypass mode
  8. 【C++11新特性】 C++11智能指针之shared_ptr
  9. Cisco路由器全局、接口、协议调试指南
  10. 移动端点击拉起输入_耐用的筛分式移动破碎站
  11. 中国电信与中国联通启动2.1GHz 5G主设备集采,规模24万站
  12. Jquery学习总结(7)——JQuery常用的10个方法总结
  13. Numbers 档案如何转Excel .xlsx 格式?
  14. 引用阿里图标库的三种方式——多色图标我选symbol
  15. H3C AC:短信认证配置
  16. 小白教程:Python爬取12306车票信息以及后期数据处理
  17. spark-submit 命令使用详解
  18. 原生Android开发自学过程(一)
  19. 苹果7如何设置手机邮箱服务器,iphone邮箱设置大全
  20. python软著申请_软著申请注意事项放心选择

热门文章

  1. 【校招VIP】“推推”Java项目课程:产品原型:产品需求要点分析
  2. 别送错了——男女之间互送礼物的含义大全 !
  3. 1.在屏幕上输出以下图案:* *** ***** ******* *********
  4. C语言——在屏幕上打印以下图案* *** *****
  5. mac装双系统win10
  6. Vue--网易云音乐移动端项目复盘
  7. 你的滤镜大师 Polarr5.11.4泼辣修图2023免费版
  8. Polarr Photo教程:通过后期增强其阳光表现力
  9. java BufferedImage(图片内存缓冲区)——批量加水印
  10. OKhttp Rejecting re-init on previously-failed class Failed resolution of: Lorg/conscrypt/Conscrypt