Apache Camel系列(2)----Hello World
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stream</artifactId>
<version>2.17.0</version>
</dependency>
</dependencies>
/**
* Hello world!
*/
public class App {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext(); // 1. 创建 CamelContext.
context.addRoutes(new RouteBuilder() {
public void configure() {
from("timer://foo?fixedRate=true&period=1000").
process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody(new Date());
}
}).to("stream:out"); // 2. 为路由配置组件或终端节点.
}
}); // 3. 添加路由到CamelContext
context.setTracing(true);
context.start(); // 4. 启动CamelContext.
Thread.sleep(Integer.MAX_VALUE); // 为了保持CamelContext处于工作状态,这里需要sleep主线程
context.stop(); // 最后停止CamelContext
}
}
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stream</artifactId>
<version>2.17.0</version>
</dependency>
</dependencies>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <bean id="myProcess" class="com.stepnetwork.test.MyProcossor"></bean> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="timer://foo?fixedRate=true&period=1000" />
<process ref="myProcess"></process>
<to uri="stream:out" />
</route>
</camelContext>
</beans>
/**
* Created by sam on 5/9/16.
*/
public class MyProcossor implements Processor {
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody(new Date().toString());
}
}
/**
* Created by sam on 5/10/16.
*/
public class App2 {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
context.start();
System.in.read();
}
}
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Tue May 10 15:23:34 CST 2016
Tue May 10 15:23:35 CST 2016 Process finished with exit code 130
Apache Camel系列(2)----Hello World的更多相关文章
- Apache Shiro系列之五,概述 —— 配置
Shiro设计的初衷就是可以运行于任何环境:无论是简单的命令行应用程序还是复杂的企业集群应用.由于运行环境的多样性,所以有多种配置机制可用于配置,本节我们将介绍Shiro内核支持的这几种配置机制. ...
- Apache Shiro系列四,概述 —— Shiro的架构
Shiro的设计目标就是让应用程序的安全管理更简单.更直观. 软件系统一般是基于用户故事来做设计.也就是我们会基于一个客户如何与这个软件系统交互来设计用户界面和服务接口.比如,你可能会说:“如 ...
- Apache Shiro系列三,概述 —— 10分钟入门
一.介绍 看完这个10分钟入门之后,你就知道如何在你的应用程序中引入和使用Shiro.以后你再在自己的应用程序中使用Shiro,也应该可以在10分钟内搞定. 二.概述 关于Shiro的废话就不多说了 ...
- Apache Camel
Apache Camel 1 import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; i ...
- Apache Camel之FTP组件学习
写在最前面 哎,最近提了离职,手头的活也基本上清理的差不多了.想着这个把月可以舒服的晃悠晃悠的离开,但是运维的小伙伴总是不架势,走之前还是提了个新需求. 先说下需求吧,我们的系统概括的讲就是一个接口系 ...
- spring boot + apache camel 传输文件
一 sftp搭建略 这里简单说一下为什么使用sftp.ftp和sftp各有优点,差别并不是太大.sftp安全性好,性能比ftp低.ftp对于java来说并不复杂,效率也高.之所以使用sftp主要是可以 ...
- apache kafka系列之Producer处理逻辑
最近研究producer的负载均衡策略,,,,我在librdkafka里边用代码实现了partition 值的轮询方法,,,但是在现场验证时,他的负载均衡不起作用,,,所以来找找原因: 下文是一篇描 ...
- [每日一学]apache camel简介
apache camel 是轻量级esb框架.如下是它的架构图: 它有几个比较重要的概念就是: 1.endpoint,所谓的endpoint,就是一种可以接收或发送数据的组件.可以支持多种协议,如jm ...
- [每日一学]apache camel|BDD方式开发apache camel|Groovy|Spock
开发apache camel应用,最好的方式就是tdd,因为camel的每个组件都是相互独立并可测试的. 现在有很多好的测试框架,用groovy的Spock框架的BDD(行为测试驱动)是比较优秀和好用 ...
- Apache Camel继承Spring Boot 实现文件远程复制和转移
pom.xml <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-f ...
随机推荐
- 浅谈Java的Mina框架传递对象
本篇文章主要讲解Java的Mina框架传递对象是什么,并附于代码和图片方便大家理解. AD:2013大数据全球技术峰会课程PPT下载 接触java的Mina框架已经有很多时间了,在网上也读过了很多的相 ...
- python之APScheduler
介绍 APScheduler是Python中一个强大的第三方库,用于在后台执行定时任务.它允许我们根据设定的时间间隔.日期规则或特定时间来执行任务,适用于定时执行脚本.定时发送邮件.定时处理数据等场景 ...
- 从零开始学java(第二天)
------------恢复内容开始------------ 今天是学习了一些基础的知识 1.注释 //行注释 /*多行注释*/ /**文档注释*/ 2.标识符和关键字 标识符就是名字,类名方法名变量 ...
- 在window 使用 docker 安装redis 踩坑记
1. 安装REDIS 在安装的时候,使用 docker pull redis 就可以了. 但是 实际上 发现镜像居然拉不下来. 修改了一下 docker 镜像. 配置如下: "registr ...
- FastExcel 合并单元格(相当的行数据,进行合并)
目录 需求 思路 实现 Excel导出单元格全量合并策略 日期格式转换 接口代码 Service DTO 使用FastExcel数据导出:官网: https://idev.cn/fastexcel/z ...
- IOS中的Context Menu
IOS中的Context Menu 通过长按组件或者3D touch方式,周边全部虚化,弹出一个可操作的菜单,并且菜单之间也可以嵌套 IOS13之后已经弃用UIViewControllerPrevie ...
- NATS: 对依赖注入支持
NuGet: NATS.Net 使用方法: serviceCollection.AddNats(); 在容器中添加了 2 个单例服务: NATS.Client.Core.NatsConnection ...
- [solon]Solon开发实战之权限认证
本项目采用权限认证框架sa-token(sa-token-solon-plugin) pom.xml <!-- 鉴权--> <dependency> <groupId&g ...
- 【前端】【H5 API】addEventListener监听网络状态的变动
WebviewObject Webview窗口对象,用于操作加载HTML页面的窗口 属性 id:webview窗口的标识 方法:监听 addEventListener 添加事件监听器 wobj.add ...
- linux shell移植,sh不支持数组及bash移植
查看此时系统shell ls -al /bin/sh Linux 操作系统缺省的 shell 是Bourne Again shell,它是 Bourne shell 的扩展,简称 Bash,与 Bou ...