Spring Boot集成 Spring Integration : 基础路由器

本文介绍了如何在Spring Boot中集成Spring Integration,并重点讲解了基础路由器的使用,包括条件路由器、拦截器的配置和应用。通过PayloadTypeRouter、HeaderValueRouter、Expression和Customized Route展示了不同类型的路由策略,并给出了元数据筛选实现的路由实例。同时,文章还讨论了拦截器的配置,说明了当拦截结果为True和False时,消息如何分别发送到不同的通道。
摘要由CSDN通过智能技术生成

如果没有浏览过之前的文章,请先浏览消息与通道的案例, 下面在 ESB 中提供了多种类型路由器

条件路由器

  • 消息数据类型 / PayloadTypeRouter
  • 元数据值 / HeaderValueRouter
  • 表达式 / Expression
  • Customized Route

下面我会提供一个根据元数据筛选实现的路由

@Configuration
public class RouteConfig {
   

	@Bean
	public IntegrationFlow routeIntegrationFlow() {
   
		return IntegrationFlows.from("routeInput")
			.route("headers['test']", m -> m.channelMapping("123", "expressChannel")
				.defaultOutputChannel("queueChannel"))
			.get();
	}

}

channelMapper的意思是如果 headers['test'] 的值为 123,那么消息会发送到 expressChannel
defaultOutputChannel 如果消息不匹配上面的映射条件都会发往默认通道queueChannel

下面是我们的测试案例

public class RouteTest extends BaseTest {
   

	@Autowired
	private MessageChannel routeInput;

	@Autowired
	private QueueChannel expressChannel;

	@Autowired
	private QueueChannel queueChannel;

	@Test
	public void contextRoute
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值