Spring Integration 子流程取决于 .handle 方法
我正在使用 spring 集成在特定重试完成后更改流程。我的 errorResponse 的 IntegrationFlow bean 如下:
@Bean
public IntegrationFlow errorMailResponse(@Qualifier(ERROR_CHANNEL) PollableChannel errorChannel) {
return IntegrationFlows.from(errorChannel)
.handle(MessagingException.class, (payload, headers) -> handleMessageException(payload),
e -> e.poller(p -> p.fixedDelay(pollerInterval)))
.channel(NO_OUTPUT_CHANNEL)
.get();
}
如果方法 handleMessageException
返回一个对象,我希望流程继续到特定通道 - MAIN_EVENTS_CHANNEL 如果 handleMessageException
返回 null,我希望继续到 NO_OUTPUT_CHANNEL 。
通过 Spring 集成可以实现吗?我尝试使用子流,但我不确定这是否是这样。 https://docs.spring.io/ spring-integration/reference/html/dsl.html#java-dsl-subflows
@Bean
public IntegrationFlow errorMailResponse(@Qualifier(ERROR_CHANNEL) PollableChannel errorChannel) {
return IntegrationFlows.from(errorChannel)
.handle(MessagingException.class, (payload, headers) -> handleMailMessageException(payload),
e -> e.poller(p -> p.fixedDelay(pollerInterval)))
.publishSubscribeChannel(subscription -> subscription
.subscribe(subflow -> subflow
.<MailPojo>handle((payload, headers) -> {
// if if result handleMessageException == null
})
.channel(NO_OUTPUT_CHANNEL))
.subscribe(subflow -> subflow
.<MailPojo>handle((payload, headers) -> {
// if result handleMessageException !=null
})
.channel(MAIN_EVENTS_CHANNEL)))
.get();
}
感谢任何帮助。
I am using spring integration to change a flow after particular retry is completed. My IntegrationFlow bean for errorResponse is as follows:
@Bean
public IntegrationFlow errorMailResponse(@Qualifier(ERROR_CHANNEL) PollableChannel errorChannel) {
return IntegrationFlows.from(errorChannel)
.handle(MessagingException.class, (payload, headers) -> handleMessageException(payload),
e -> e.poller(p -> p.fixedDelay(pollerInterval)))
.channel(NO_OUTPUT_CHANNEL)
.get();
}
If method handleMessageException
returns an object I want the flow to continue to particular channel - MAIN_EVENTS_CHANNEL if handleMessageException
returns null I want to continue to NO_OUTPUT_CHANNEL.
Is that possible to achieve with Spring integration? I tried to use subflow but I am not sure if it is the way. https://docs.spring.io/spring-integration/reference/html/dsl.html#java-dsl-subflows
@Bean
public IntegrationFlow errorMailResponse(@Qualifier(ERROR_CHANNEL) PollableChannel errorChannel) {
return IntegrationFlows.from(errorChannel)
.handle(MessagingException.class, (payload, headers) -> handleMailMessageException(payload),
e -> e.poller(p -> p.fixedDelay(pollerInterval)))
.publishSubscribeChannel(subscription -> subscription
.subscribe(subflow -> subflow
.<MailPojo>handle((payload, headers) -> {
// if if result handleMessageException == null
})
.channel(NO_OUTPUT_CHANNEL))
.subscribe(subflow -> subflow
.<MailPojo>handle((payload, headers) -> {
// if result handleMessageException !=null
})
.channel(MAIN_EVENTS_CHANNEL)))
.get();
}
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,
null
不是payload
。因此,消息传递在大多数情况下不支持null
。集成流程仅在返回 null 时停止:https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#service-activator-namespace< /a>因此,您做出逻辑决定的假设对于 Spring Integration 来说是不正确的。您需要考虑什么可以用作此类
NO_OUTPUT_CHANNEL
的信号。您可以创建一个人工NullType
并使用PayloadTypeRouter
来根据handleMailMessageException()
返回的有效负载类型确定下一步何时进行:另一种方法就是使用一个
Optional
并在router函数中检查它的内容。无论哪种方式,您都需要使用路由器。First of all the
null
is not apayload
. Therefore messaging does not supportnull
in most cases. The integration flow just stops at the point where you returnnull
: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#service-activator-namespaceSo, your assumption to make a logical decision is not correct with Spring Integration. You need to think about something what could be used as a signal for such a
NO_OUTPUT_CHANNEL
. You can create an artificialNullType
and use aPayloadTypeRouter
to determine when to go next according the payload type returned from yourhandleMailMessageException()
:Another way is to use an
Optional
and check its content in the router function. Either way you need to use a router.