Stardust/Knowledge Base/Integration/Spring Integration
Spring Integration is a light-weight framework that follows the Spring programming model and aims to implement well-known Enterprise Integration Patterns. It allows you to declaratively create a chain of message consuming and message producing components with capabilities for message routing, filtering, etc.
You can easily use existing Pojos as parts of this 'message bus' without any need to change them or you can extend the framework's adapters to have greater control over the message handling behavior.The following is an example for using Spring Integration with Stardust involving the handling of incoming files and a document repository.
File Archiver Example
This example consists of a Spring Integration solution with 3 components: The first is capable of monitoring a directory for incoming files, the second archives the file into a folder inside a JCR content repository (using Stardust's Document Management Service), and the third component starts a process in the Stardust runtime passing in the ID of the archived document to create an attachment.
Inbound File Adapter
This is an out-of-the-box Spring Integration adapter which monitors a directory for new files. Here's a configuration example in which a directory is polled every 3 seconds for new files starting with the name "test*" and every file processed is cached in a filter so it's not picked up a again in the next polling interval.. You can also see that every detected file is sent to the "fileMessages" channel.
<!-- Inbound adapter reading files from a directory --> <file:inbound-channel-adapter directory="file:C:/temp/incoming" channel="fileMessages" filter="incomingFileFilter" />
<!-- Poller for incoming files -->
<si:poller default="true" max-messages-per-poll="10"> <si:interval-trigger interval="3" time-unit="SECONDS" /></si:poller>
<!-- Customized composite filter for incoming files -->
<bean id="incomingFileFilter" class="org.springframework.integration.file.CompositeFileListFilter"> <constructor-arg> <list> <bean class="org.springframework.integration.file.AcceptOnceFileListFilter" /> <bean class="org.springframework.integration.file.PatternMatchingFileListFilter"> <constructor-arg value="^test.*$"/> </bean> </list> </constructor-arg> </bean>
JCR File Archive Service
In the below example, first of all, you see how a Spring Integration service-activator is defined to consume messages on the input-channel "fileMessages" using the custom jcrFileArchiveService. The output (wich consists merely of the JCR ID of the archived document) is then sent on to the output-channel "jcrFileMessages".
The JcrFileArchiveService class is a custom component which provides a thin wrapper around the Stardust DMS File Archiver and is capable of handling a message with a file payload. The wrapped Stardust DMS File Archiver connects to Stardust via Spring Remoting or EJB Remoting and it uses the DocumentManagementService to archive a document in a specific, configurable location.