Spring Java DSL Integration - @ServiceActivator method with @Header parameter annotations

I have a Spring Integration 4 bean method with the following signature:

@Component
public class AService {

    @ServiceActivator
    public Message<?> serviceMethod(
            Message<?> message,
            @Header(ServiceHeader.A_STATE) AState state,
            @Header(ServiceHeader.A_ID) String id) {

        ...
    }

    ...
}

      

I am currently calling this service method from a Spring Integration Java DSL thread (spring-integration-java-dsl: 1.0.1.RELEASE) like this:

.handle("aService", "serviceMethod")

      

This works absolutely fine, but I'm wondering if a service method can be called like this:

.handle(Message.class, (m, h) -> aService.serviceMethod(m, h))

      

The reason I would like to call a service method this way is because when someone looks at the code using an IDE like Eclipse, they can drill into that service method, for example highlighting the method and hitting F3.

So my question is, is there an alternative way to call the method @ServiceActivator

(which includes annotations @Header

) without using strings for the service / method name of the service in .handle()

?

+3


source to share


1 answer


Not really, you can't pass the entire message and selected headers, but you can pass the payload and individual headers ...

.handle(String.class, (p, h) -> aService().serviceMethod(p, 
     (AState) h.get(ServiceHeader.A_STATE),
     (String) h.get(ServiceHeader.A_ID)))

      

(assuming the payload is String

).

Note that annotations @Header

are meaningless in this scenario because you are directly pulling the headers in the lambda expression.

It also does not need to be annotated as @ServiceActivator

; you can call any bean method this way.



public Message<?> serviceMethod(
        String payload, AState state, String id) {

    ...
}

      

.handle("aService", "serviceMethod")

      

variation is where all the magic happens (matching message content to method parameters). Of course, we can't do magic if you want to call a method directly in Java.

+3


source







All Articles