关于Spring-Integration的介绍这里不需要赘述,现在我们需要实现的是发送一个param,里面有两个参数dataType和data,dataType是0和1除外的舍弃,剩余dataType=0的数据往oldChannel通道发,剩余dataType=1的数据往newChannel通道发,消费数据并且打印

1,配置文件 : application.xml

<beans:beans xmlns="http://www.springframework.org/schema/integration"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:beans="http://www.springframework.org/schema/beans"xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans.xsd  http://www.springframework.org/schema/integration  http://www.springframework.org/schema/integration/spring-integration.xsd"><!-- 要输入的信息往这个通道里塞即可 -->
<channel id="inputChannel" /><!--  这个过滤器可以过滤一些非法信息,重组消息体等  -->
<splitter input-channel="inputChannel" ref="splitService" output-channel="afterSplitChannel" /><!-- 路由转发,重新转发到另外的通道去 getDistritChannelId方法返回的是另外通道的id的名称 -->
<router input-channel="afterSplitChannel" ref="routerService" method="getDistritChannelId" /><service-activator input-channel="oldChannel" ref="doConsumerService"  method="printOldMsg" /><service-activator input-channel="newChannel" ref="doConsumerService"  method="printNewMsg" /><!-- 处理过滤器的业务方法,需要继承spring-integration  core里面的 AbstractMessageSplitter -->
<beans:bean id="splitService" class="com.test.SplitService" /><!-- 路由业务处理类,里面一定需要getDistritChannelId方法返回通道的id的名称 -->
<beans:bean id="routerService" class="com.test.RouterService" /><!-- 通道消费端消费信息,里面需要有上面需要用到的printOldMsg和printNewMsg方法 -->
<beans:bean id="doConsumerService" class="com.test.DoConsumerService" /></beans:beans>

2,com.test.SplitService:

public class SplitService extends AbstractMessageSplitter {@Overrideprotected Object splitMessage(Message<?> msg) {if(msg.getPayload() == null) {return null;}Param param = (Param)msg.getPayload();if(param.getDataType !=0 || param.getDataType !=1) {return null;}//可以重新对param进行处理后再返回return param;}}

3,com.test.Param :

public class Param {private Integer dataType;private Object data;public Integer getDataType() {return this.dataType;}public Integer getData() {return this.data;}public void setDataType(Integer dataType) {this.dataType = dataType;}public void setData(Object data) {this.data = data;}
}

4,com.test.RouterService

/**路由重定向*/
public class RouterService {public String getDistritChannelId(Param param) {if(param.getDataType==0) {return "oldChannel";}if(param.getDataType==1) {return "newChannel";}return "oldChannel";}
}

5,com.test.DoConsumerService

public class DoConsumerService{public void printOldMsg(Param param) {System.out.println("--------处理Old通道信息:" + param);}public void printNewMsg(Param param) {System.out.println("--------处理New通道信息:" + param);}}

6,Main-来发送信息:

public class Main{public static void main(String[] args) {ApplicationContext app = new ClassPathXmlApplicationContext("classpath:application.xml");MessageChannel msgChannel = app.getBean("inputChannel",MessageChannel.class);Param param = new Param();for(int i = 0; i < 100; i++) {if(i % 2 == 0) {param.setDataType(0);} else {param.setDataType(1);}param.setData("{\"sum\":" + i + "}");Message<Param> msg = MessageBuilder.withPayload(param).build();msgChannel.send(msg);}}}

Spring Integration基本用法相关推荐

  1. Spring Integration入门

    为什么使用Spring IntegrationSpring Integration是Spring框架创建的又一个API,面向企业应用集成(EAI).说到集成,并不缺"解决办法":硬 ...

  2. pmp访谈法和焦点小组区别_访谈和书评:Spring Integration in Action

    pmp访谈法和焦点小组区别 由Mark Fisher,Jonas Partner,Marius Bogoevici和Iwein Fuld撰写的< Spring Integration in Ac ...

  3. #翻译NO.3# --- Spring Integration Framework

    为什么80%的码农都做不了架构师?>>>    2.4 Message Endpoints A Message Endpoint represents the "filte ...

  4. Spring Integration学习资料

    Spring Integration学习资料 1.1     背景 Spring框架的一个重要主题是控制反转.从广义上来说,Spring处理其上下文中管理的组件的职责.只要组件减轻了职责,它们同时也被 ...

  5. Spring Integration 4.3.10 发布,Spring 消息通信

    Spring Integration 4.3.10 发布了.Spring Integration 能在基于 Spring 的应用中进行简单的消息通信,并通过简单的适配器与外部系统集成.这些适配器提供了 ...

  6. #翻译NO.5# --- Spring Integration Framework

    为什么80%的码农都做不了架构师?>>>    本人觉得这一章很重要,那就是 Spring默认的channel 的实现 DirectChannel,这个要大家多按照原文理解,开发者为 ...

  7. ESB学习笔记(Spring Integration实战)

    http://wangleifire.iteye.com/blog/351749 介绍 Spring Integration是Spring公司的一套ESB框架. 前面ESB介绍中我也做了一定了解.我们 ...

  8. #翻译NO.4# --- Spring Integration Framework

    为什么80%的码农都做不了架构师?>>>    Part III. Core Messaging This section covers all aspects of the cor ...

  9. java中channelmessage,MessageStore支持的QueueChannel与Spring Integration Java Config

    Spring Integration reference guide指的是使用MessageStore实现为QueueChannel提供持久性. 提到了很多次,但是所有示例都使用XML配置,即 但是Q ...

最新文章

  1. ELK 搭建 TB 级海量日志监控系统,这个太强了!
  2. java之final
  3. centos安装zendopcache
  4. 干货总结:I2C总线详细要点
  5. 麒麟信安:“一云多芯”信创云桌面解决方案引领者
  6. PostgresSQL模式
  7. 【背包问题】基于matlab多目标粒子群算法求解多背包问题【含Matlab源码 654期】
  8. 冲动的惩罚 - 刀郎 - 新阿瓦尔古丽
  9. 计算机telnet命令大全,Telnet命令
  10. 使用matplotlib动态打印图片(RGB图片)
  11. 41-牛栏-最短路径
  12. GBase 8c 的安全特性
  13. cesium加载动图方案三:通过apng-js库实现
  14. 导入另一个 Git库到现有的Git库并保留提交记录
  15. 算法学习之道,应有三重境界
  16. biu biu biu
  17. 未来五年有颠覆性的IT技术都在这里
  18. Java web 项目技术文档目录结构
  19. Go语言bufio包(读与写)
  20. 删除buddypress相关功能

热门文章

  1. 关键字和关键字优化(转)
  2. 人人都是系统装机高手,利用windows官方的工具,安装超简单
  3. CGAL 点云法向量重定向(扫描线算法)
  4. 高性能MySQL读书笔记
  5. Minecraft PCL 启动器
  6. ios中图层的用法(1)
  7. 校园商战大赛备战攻略
  8. 对自动变速器的控制器建模
  9. 你还在担心你的 IP 被封吗?
  10. GTSAM在windows下安装,配置,简单调试