如果没有浏览过之前的文章,请先浏览消息与通道的案例, 下面在 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