An API gateway is an application-facing interface for sending messages into an integration flow. In Spring Integration, it is declared as a Java interface; the framework generates its implementation at runtime, so application code calls methods instead of constructing messages directly. section 10.1 section 10.2.7
A gateway controls how method calls become messages:
- Route requests through a named message channel with @MessagingGateway(defaultRequestChannel="textInChannel"). section 10.1
- Carry ordinary method arguments in the message payload, while @Header places selected arguments in message headers such as FileHeaders.FILENAME. section 10.1
- Choose one-way behavior with a void method or two-way behavior by returning a value from a reply channel. section 10.2.7
Writing text to a file
A FileWriterGateway accepts a filename and text. The filename becomes a file-name header, the text becomes the payload, and the request enters textInChannel for the rest of the flow to process. A two-way UpperCaseGateway instead sends a String through inChannel and returns the transformed result from outChannel. section 10.1 section 10.2.7
Listing 10.1 Message gateway interface to transform method invocations into messages
package sia6;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.integration.file.FileHeaders;
import org.springframework.messaging.handler.annotation.Header;
@MessagingGateway(defaultRequestChannel="textInChannel") #1
public interface FileWriterGateway {
void writeToFile(
@Header(FileHeaders.FILENAME) String filename, #2
String data);
}
Use the complete gateway listing to see @MessagingGateway, the default request channel, and the header annotation together. section 10.1
package sia6;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.stereotype.Component;
@Component
@MessagingGateway(defaultRequestChannel="inChannel",
defaultReplyChannel="outChannel")
public interface UpperCaseGateway {
String uppercase(String in);
}
Compare a two-way gateway declaration that specifies both request and reply channels. section 10.2.7





