0
votes

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?

More specifically, assuming the below IntegrationFlow definition...

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? 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. If this is the recommended solution, that is fine.

1

1 Answers

2
votes

That's correct. It is really non-formal pattern to stop processing returning a null from the service method. 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

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.

You also can achieve a discard-and-log goal with a filter().