1
votes

I have seen in many cases the .handle("someBean", "someMethod") EIP method, playing vast role in the integration flows. I can understand that it is just a Service Activator in the former XML Config, but I need some clarification on how to create this bean and what does the someMethod return. Also, in which cases do I have to use .handle(...)? Maybe a completed example using Java DSL should work for me.

1

1 Answers

1
votes

As noticed correctly the .handle("someBean", "someMethod") is fully equal to the <int:service-activator ref="someBean" method="someMethod"/>: https://docs.spring.io/spring-integration/reference/html/messaging-endpoints-chapter.html#service-activator-namespace.

That means that you should have someBean definition for service invocation in the someMethod. For example you need to perform simple logic to convert payload of the incoming message to the upper case and return the result:

class MyService {

   public String someMethod(String payload) {
        return payload.toUpperCase();
   }

}

The return of this method becomes as a payload of the outbound message to the next EIP endpoint in your IntegrationFlow definition.

Everything what you see in the Reference Manual is fully true for Java DSL. In particular all the rules for the <service-activator> or @ServiceActivator are applied for this .handle().