[英]Discarding a Message within a Spring Integration DSL Service Activator
Is there a way that we can discard a message from within a Spring Integration Service Activator that is defined using the Spring Integration DSL .handle()
method?有没有办法可以从使用 Spring Integration DSL
.handle()
方法定义的 Spring Integration Service Activator 中丢弃消息?
More specifically, assuming the below IntegrationFlow definition...更具体地说,假设下面的 IntegrationFlow 定义......
public IntegrationFlow sampleFlow() {
return IntegrationFlows
.from("someChannel")
.handle(someServiceClass::someMethod)
.get();
}
Is there a way to have a message discarded based on some evaluation within the someMethod
definition?有没有办法根据
someMethod
定义中的某些评估丢弃消息? Ideally, I would like to perform some logging and then discard.理想情况下,我想执行一些日志记录然后丢弃。
I have found is that returning null
from someMethod
seems to effectively end the flow but I am not sure if this is the most graceful/correct solution.我发现从
someMethod
返回null
似乎有效地结束了流程,但我不确定这是否是最优雅/正确的解决方案。 If this is the recommended solution, that is fine.如果这是推荐的解决方案,那很好。
That's correct.没错。 It is really non-formal pattern to stop processing returning a
null
from the service method.停止处理从服务方法返回
null
确实是一种非正式的模式。 We even have documented it in non-official manner: https://docs.spring.io/spring-integration/docs/5.2.3.RELEASE/reference/html/messaging-endpoints.html#service-activator-namespace我们甚至以非官方的方式记录了它: https : //docs.spring.io/spring-integration/docs/5.2.3.RELEASE/reference/html/messaging-endpoints.html#service-activator-namespace
The service activator is one of those components that is not required to produce a reply message.
服务激活器是不需要生成回复消息的组件之一。 If your method returns null or has a void return type, the service activator exits after the method invocation, without any signals.
如果您的方法返回 null 或具有 void 返回类型,则服务激活器在方法调用后退出,没有任何信号。
You also can achieve a discard-and-log goal with a filter()
.您还可以使用
filter()
实现丢弃和记录目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.