File Adapters
File Adapters fetch or copy files to and from different file
systems. They pick a file from a file system and turn into Framework’s
Message to publish onto a channel and
vice versa. Framework supports a declarative model using file namespace. It also provides a few classes
for reading and writing files, but using namespace is advised.
Using Namespace
The file namespace provides the
respective elements to create the objects declaratively and easily. In
order to use the file namespace, you should add the
respective schema urls to your XML file, highlighted in bold
below:
<?xml version="1.0" encoding="UTF-8"?> <beans .... xmlns:file="http://www.springframework.org/schema/integration/file" xsi:schemaLocation= http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-2.1.xsd"> ... </beans>
Framework provides two adapters to read and write the files. The
inbound-channel-adapter element is
used for reading the files and publishing them onto a channel as
File payload messages. The outbound-channel-adapter is used for picking
up the File payload messages from a
channel, extracting them as files, and writing them to the file
systems.
Inbound File Adapter
The following snippet demonstrates the inbound adapter:
<!-- Adapter using namespace --> <file:inbound-channel-adapter id="fileAdapter" directory="/Users/mkonda/dev/ws/" channel="files-out-channel"> <int:poller fixed-rate="1000" /> </file:inbound-channel-adapter> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access