简体   繁体   English

在 Spring Integration DSL 服务激活器中丢弃消息

[英]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.

相关问题 Spring Integration Java Config / DSL中没有方法的服务激活器 - Service Activator without method in Spring Integration Java Config / DSL JUnit for Spring Integration Activator,返回类型为Message <?> - JUnit for Spring Integration Activator with return type Message<?> Spring 集成:如何通过服务激活器作为并行服务使多线程从可轮询通道轮询消息 - Spring integration: how to make multi thread to poll message from a pollable channel through service activator as a paraller service 没有输出通道的Spring Integration Service Activator - Spring Integration Service Activator Without Output Channel 在服务激活器中选择重载方法(Spring集成) - choose overloaded method in service activator (Spring Integration) 如何在Spring Integration中动态调用Service Activator - How to call Service Activator dynamically in spring Integration 具有多条消息的Spring Integration Service Activator - Spring integration service activator with multiple messages 了解弹簧集成服务激活器 - Understanding spring-integration service-activator Spring Integration将网关连接到服务激活器 - Spring Integration Connecting a Gateway to a Service Activator Spring集成中的服务激活器组件是什么? - What is service activator component in spring integration?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM