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> ...
Get Just Spring Integration now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.