Apache Camel系列(3)----Redis组件
<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-spring-redis</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="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="localhost" />
<property name="port" value="9999" />
<property name="password" value="1234567890" />
</bean>
<bean id="serializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" /> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route startupOrder="1">
<from uri="timer://foo?fixedRate=true&period=1000"/>
<setHeader headerName="CamelRedis.Command">
<constant>SET</constant>
</setHeader>
<setHeader headerName="CamelRedis.Key">
<constant>keyOne</constant>
</setHeader>
<setHeader headerName="CamelRedis.Value">
<constant>valueOne</constant>
</setHeader>
<to uri="spring-redis://localhost:9999?connectionFactory=#connectionFactory&serializer=#serializer"/>
</route>
</camelContext>
</beans>
<?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="serializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" /> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route startupOrder="1">
<from uri="timer://foo?fixedRate=true&period=1000"/>
<setHeader headerName="CamelRedis.Command">
<constant>SET</constant>
</setHeader>
<setHeader headerName="CamelRedis.Key">
<constant>keyOne</constant>
</setHeader>
<setHeader headerName="CamelRedis.Value">
<constant>valueOne</constant>
</setHeader>
<to uri="spring-redis://localhost:9999?serializer=#serializer"/>
</route>
</camelContext>
</beans>
/**
* Created by sam on 5/10/16.
*/
public class App3 {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
context.start();
System.in.read();
}
}
[sam@localhost redis-2.8.19]$ src/redis-cli -p 9999 -a 1234567890
127.0.0.1:9999> MONITOR
OK
1462931627.929228 [0 127.0.0.1:50939] "PING"
1462931686.110952 [0 127.0.0.1:50943] "AUTH" "1234567890"
1462931686.120240 [0 127.0.0.1:50943] "SET" "keyOne" "valueOne"
1462931687.065705 [0 127.0.0.1:50943] "SET" "keyOne" "valueOne"
1462931688.066442 [0 127.0.0.1:50943] "SET" "keyOne" "valueOne"
1462931689.066169 [0 127.0.0.1:50943] "SET" "keyOne" "valueOne"
1462931690.065948 [0 127.0.0.1:50943] "SET" "keyOne" "valueOne"
1462931691.065674 [0 127.0.0.1:50943] "SET" "keyOne" "valueOne"
public class App4 {
public static void main(String[] args) throws Exception {
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(); // 创建connectionFactory
connectionFactory.setHostName("localhost");
connectionFactory.setPassword("1234567890");
connectionFactory.setPort(9999);
SimpleRegistry registry = new SimpleRegistry();
connectionFactory.afterPropertiesSet(); // 必须要调用该方法来初始化connectionFactory
registry.put("connectionFactory", connectionFactory); //注册connectionFactory
registry.put("serializer", new StringRedisSerializer()); //注册serializer
CamelContext context = new DefaultCamelContext(registry);
context.addRoutes(new RouteBuilder() {
public void configure() {
errorHandler(deadLetterChannel("stream:out"));
from("timer://foo?fixedRate=true&period=1000").
setHeader("CamelRedis.Command", constant("PUBLISH")).
setHeader("CamelRedis.Channel", constant("testChannel")).
setHeader("CamelRedis.Message", constant(new Date().toString())).
to("spring-redis://localhost:9999?connectionFactory=#connectionFactory&serializer=#serializer");
}
});
context.setTracing(true);
context.start();
Thread.sleep(Integer.MAX_VALUE);
context.stop();
}
}
public class App4 {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
errorHandler(deadLetterChannel("stream:out"));
from("timer://foo?fixedRate=true&period=1000").
setHeader("CamelRedis.Command", constant("PUBLISH")).
setHeader("CamelRedis.Channel", constant("testChannel")).
setHeader("CamelRedis.Message", constant(new Date().toString())).
to("spring-redis://localhost:9999");
}
});
context.setTracing(true);
context.start();
Thread.sleep(Integer.MAX_VALUE);
context.stop();
}
}
Apache Camel系列(3)----Redis组件的更多相关文章
- Apache Camel之FTP组件学习
写在最前面 哎,最近提了离职,手头的活也基本上清理的差不多了.想着这个把月可以舒服的晃悠晃悠的离开,但是运维的小伙伴总是不架势,走之前还是提了个新需求. 先说下需求吧,我们的系统概括的讲就是一个接口系 ...
- spring boot + apache camel 传输文件
一 sftp搭建略 这里简单说一下为什么使用sftp.ftp和sftp各有优点,差别并不是太大.sftp安全性好,性能比ftp低.ftp对于java来说并不复杂,效率也高.之所以使用sftp主要是可以 ...
- Apache Shiro系列之五,概述 —— 配置
Shiro设计的初衷就是可以运行于任何环境:无论是简单的命令行应用程序还是复杂的企业集群应用.由于运行环境的多样性,所以有多种配置机制可用于配置,本节我们将介绍Shiro内核支持的这几种配置机制. ...
- Apache Shiro系列四,概述 —— Shiro的架构
Shiro的设计目标就是让应用程序的安全管理更简单.更直观. 软件系统一般是基于用户故事来做设计.也就是我们会基于一个客户如何与这个软件系统交互来设计用户界面和服务接口.比如,你可能会说:“如 ...
- 在Apache Tomcat 7设置redis作为session store
在Apache Tomcat 7设置redis作为session store //输出tomcat控制台日志 root@ubuntu:~# cd /usr/tomcat/apache-tomcat- ...
- [每日一学]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 ...
- Apache Camel 与 Spring Boot 集成,通过FTP定时采集、处理文件 (转)
1.概要: 本项目主要是通过在Spring平台上配置Camel.FTP,实现定时从FTP服务器下载文件到本地.解析文件.存入数据库等功能. 2.搭建空项目: Spring Boot有几种自动生成空项目 ...
- Apache Shiro系列三,概述 —— 10分钟入门
一.介绍 看完这个10分钟入门之后,你就知道如何在你的应用程序中引入和使用Shiro.以后你再在自己的应用程序中使用Shiro,也应该可以在10分钟内搞定. 二.概述 关于Shiro的废话就不多说了 ...
随机推荐
- Java深度历险(四)——Java垃圾回收机制与引用类型
Java语言的一个重要特性是引入了自动的内存管理机制,使得开发人员不用自己来管理应用中的内存.C/C++开发人员需要通过malloc/free 和new/delete等函数来显式的分配和释放内存.这对 ...
- mysql5.7之JSON数据类型
1.json对象 1.1.方法 使用对象操作的方法进行查询:字段->'$.json属性' 使用函数进行查询:json_extract(字段, '$.json属性') 获取JSON数组/对象长度: ...
- PythonDay3Advance
PythonDay3Advance 运算符 位运算符 进制: 将整数分了几种进制表示法 二进制:由0,1构成,逢2进1,以0b开头 八进制:由0,1,2,3,4,5,6,7构成,逢8进1,以0开头 十 ...
- kube-apiserver 高可用,keepalived + haproxy
为什么要做高可用 在生产环境中,kubernetes 集群中会多多个 master 节点,每个 master 节点上都会部署 kube-apiserver 服务,实现高可用.但是 client 访问 ...
- 斐波那契数列(Java实现)
斐波那契数列 题目描述: 悲波那契数列(Fibonacci sequence)又称黄金分割数列,因数学家莱昂纳多·裴波那契(LeonardodaFibonacci)以兔子繁殖为例子而引入,故又称为&q ...
- 【分块】LibreOJ 6279 数列分块入门3
题目 https://loj.ac/p/6279 题解 将 \(n\) 个元素的数组 \(a\) 按块长 \(\sqrt{n}\) 进行分块处理.为每个块设置一个懒添加标记 \(add[i]\),代表 ...
- cas5开启Restful接口验证
POM文件中加入rest依赖: <!-- Restful support --> <dependency> <groupId>org.apereo.cas< ...
- Qt/C++原创项目作品精选(祖传原创/性能凶残/界面精美)
00 前言说明 从事Qt开发十年有余,一开始是做C#.NET开发的,因为项目需要,转行做嵌入式linux开发,在嵌入式linux上做可视化界面开发一般首选Qt,当然现在可选的方案很多比如安卓,但是十多 ...
- [转]Spring Security打造一个简单Login登录页面,实现登录+跳转+注销+角色权限功能,核心代码不到100行!
原文链接:Spring Security打造一个简单Login登录页面,实现登录+跳转+注销+角色权限功能,核心代码不到100行!
- 网络编程懒人入门(十三):一泡尿的时间,快速搞懂TCP和UDP的区别
本文引用了作者Fundebug的"一文搞懂TCP与UDP的区别"一文的内容,感谢无私分享. 1.引言 网络协议是每个搞网络通信应用开发(比如IM.推送.网关等等)的程序员都必须要掌 ...