Spring 集成 WireTap 选择器不起作用
Spring Integration WireTap Selector doesn't work
我在 DSL 中创建 IntegrationFlows:
return IntegrationFlows
.from(yieldCurveConversionResultChannel)
.wireTap(notificationChannel, wt -> wt.selector(m -> (m.getPayload() instanceof Throwable)))
.get();
在wireTap的选择器中,我试图过滤消息负载是Exception的实例。
还有一个 Flow 来处理通知服务。
return IntegrationFlows
.from(notificationChannel)
.handle(commonNotificationService)
.get();
不过好像不行。我可以得到有效负载不是异常实例的消息。
以前有人遇到过这个问题吗?或者我弄错了什么?
非常感谢。
效果很好:
@SpringBootApplication
public class So66813194Application {
public static void main(String[] args) {
SpringApplication.run(So66813194Application.class, args);
}
@Bean
IntegrationFlow flow() {
return IntegrationFlows
.from("yieldCurveConversionResultChannel")
.wireTap(notificationChannel(), wt -> wt.selector(m -> (m.getPayload() instanceof Throwable)))
.get();
}
@Bean
MessageChannel notificationChannel() {
return new DirectChannel();
}
@Bean
IntegrationFlow notification() {
return IntegrationFlows
.from(notificationChannel())
.handle(System.out::println)
.get();
}
}
@SpringBootTest
class So66813194ApplicationTests {
@Autowired
MessageChannel yieldCurveConversionResultChannel;
@Test
void contextLoads() {
this.yieldCurveConversionResultChannel.send(new GenericMessage<>("foo"));
this.yieldCurveConversionResultChannel.send(new GenericMessage<>(new RuntimeException()));
}
}
我在控制台中只看到这个:
2021-03-26 09:36:25.367 INFO 15164 --- [ main] o.s.i.s.s.So66813194ApplicationTests : Started So66813194ApplicationTests in 1.229 seconds (JVM running for 2.365)
GenericMessage [payload=java.lang.RuntimeException, headers={id=85633b3f-7a17-6b70-8a34-9cbc5aacbf5b, timestamp=1616765785796}]
2021-03-26 09:36:25.810 INFO 15164 --- [extShutdownHook] o.s.i.endpoint.EventDrivenConsumer : Removing {bridge} as a subscriber to the 'yieldCurveConversionResultChannel' channel
因此,来自我的测试的 foo
消息确实被选择器拒绝了。
也许你的问题是某些进程直接向此 notificationChannel
发送消息 - 而不是通过提到的 WireTap
...
我在 DSL 中创建 IntegrationFlows:
return IntegrationFlows
.from(yieldCurveConversionResultChannel)
.wireTap(notificationChannel, wt -> wt.selector(m -> (m.getPayload() instanceof Throwable)))
.get();
在wireTap的选择器中,我试图过滤消息负载是Exception的实例。
还有一个 Flow 来处理通知服务。
return IntegrationFlows
.from(notificationChannel)
.handle(commonNotificationService)
.get();
不过好像不行。我可以得到有效负载不是异常实例的消息。
以前有人遇到过这个问题吗?或者我弄错了什么?
非常感谢。
效果很好:
@SpringBootApplication
public class So66813194Application {
public static void main(String[] args) {
SpringApplication.run(So66813194Application.class, args);
}
@Bean
IntegrationFlow flow() {
return IntegrationFlows
.from("yieldCurveConversionResultChannel")
.wireTap(notificationChannel(), wt -> wt.selector(m -> (m.getPayload() instanceof Throwable)))
.get();
}
@Bean
MessageChannel notificationChannel() {
return new DirectChannel();
}
@Bean
IntegrationFlow notification() {
return IntegrationFlows
.from(notificationChannel())
.handle(System.out::println)
.get();
}
}
@SpringBootTest
class So66813194ApplicationTests {
@Autowired
MessageChannel yieldCurveConversionResultChannel;
@Test
void contextLoads() {
this.yieldCurveConversionResultChannel.send(new GenericMessage<>("foo"));
this.yieldCurveConversionResultChannel.send(new GenericMessage<>(new RuntimeException()));
}
}
我在控制台中只看到这个:
2021-03-26 09:36:25.367 INFO 15164 --- [ main] o.s.i.s.s.So66813194ApplicationTests : Started So66813194ApplicationTests in 1.229 seconds (JVM running for 2.365)
GenericMessage [payload=java.lang.RuntimeException, headers={id=85633b3f-7a17-6b70-8a34-9cbc5aacbf5b, timestamp=1616765785796}]
2021-03-26 09:36:25.810 INFO 15164 --- [extShutdownHook] o.s.i.endpoint.EventDrivenConsumer : Removing {bridge} as a subscriber to the 'yieldCurveConversionResultChannel' channel
因此,来自我的测试的 foo
消息确实被选择器拒绝了。
也许你的问题是某些进程直接向此 notificationChannel
发送消息 - 而不是通过提到的 WireTap
...