I was having two issues, I couldn't find out what annotations to use to get the same effects as the 'gateway' xml element found in the documentation. When I solved that problem I couldn't figure out why my gateway was never replying!
So I figured both these out and thought I'd share.
Here's how I defined my gateway class:
@MessagingGateway(defaultRequestChannel = "inChan", defaultReplyChannel = "outChan" )
public interface CalAmpSIRouteAndProcessService {
@Gateway(requestChannel = "inChan", replyChannel = "outChan" )
Future<CalAmpSIWrapper> processMessage(Object message, @Header("headerKey") String neededHeader);
}
This gives you an asynchronous service method (processMessage), the Object class in the message can be any class you like for the service. The @Header gives your service method the ability to append a header value (with key "headerKey" and value neededHeader) to the message produced by the processMessage call.
To get this component recognized, I needed the following annotations in my MyConfig.java class:
@Configuration
@ComponentScan
@EnableIntegration
@IntegrationComponentScan
Ok, finally this issue with getting a reply from the gateway. It turns out that the reply mechanism of the gateway depends on some tokens passed in the message header. So if your service involves some message transforms that will each compose a new message with for example MessageBuilder then the response token for the original request is lost! It will still be lost even if you use the ".fromMessage(inboundMessage)" in the transform. What is needed to preserve the value is the "copyHeaders" method. I'll give my example below, this is for a transformer type:
m1 = MessageBuilder
.withPayload(transformedOutboundPayload)
.copyHeaders(messageIn.getHeaders())
.setHeader("headerKey", transformedHeaderValue)
.build();
The set header line isn't necessary in all cases, I needed it because my transformers were modifying both payload and header.
Ok, I hope this helps someone!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With