...
The ServiceMix File component provides JBI integration to the file system. It can be used to read & write files via URI or to periodically poll directories for new files.
Note that this component is only available in releases >= 3.1.
URI
You can use the familiar file URI to communicate with files
Code Block |
---|
file:foo.xml
file://path/to/something
|
Endpoints
Code Block |
---|
lang | xml |
---|
title | Provider endpoint |
---|
|
<file:sender service="test:service"
endpoint="endpoint"
directory="file:target/pollerFiles" />
|
Maven Archetype
The servicemix-file-service-unit archetype creates a File Service Unit which contains both poller and sender endpoints sample:
Code Block |
---|
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-file-service-unit \
-DarchetypeVersion=2010.01 \
-DgroupId=your.group.id \
-DartifactId=your.artifact.id \
-Dversion=your-version
|
Once you've customized the service unit, simply install the SU:
Info |
---|
Remember that to be deployable in ServiceMix, the ServiceUnit has to be embedded in a Service Assembly: only the Service Assembly zip file can be deployed in ServiceMix. To add your SU in a SA, you need to define it in the dependency sets: Code Block |
---|
<dependency>
<groupId>your.group.id</groupId>
<artifactId>your.artifact.id</artifactId>
<version>your-version</version>
</dependency>
|
|
Endpoints Configuration
Poller Endpoint
The File Poller endpoint polls file in a given directory, read it using the marshaler, and send marshaled file content to the NMR.
Code Block |
---|
lang | xml |
---|
title | Polling Poller (consumerConsumer) endpointEndpoint |
---|
|
<file:poller service="test:poller"
endpoint="poller"
targetService="test:receiver"
file="file:target/pollerFiles" />
|
Note |
---|
Poller generates an InOnly message. |
Info |
---|
title | Poller endpoint attributesEndpoint Attributes |
---|
borderStyle | solidbgColor='lighblue' |
---|
|
Name | Type | Description | Default |
---|
service | QName | the service name of the endpoint | required to be spec'd | endpoint | string | the endpoint name of the endpoint | required to be spec'd | interfaceName | QName | the interface name of the endpoint | | targetService | QName | the service name of the target endpoint | | targetEndpoint | string | the endpoint name of the target endpoint | | targetInterface | QName | the interface name of the target endpoint | | targetUri | string | the uri of the target endpoint | | autoCreateDirectory | boolean | creates dir if doesn't exist | true | firstTime | date | datetime before first poll can take place | null (first poll right after start) | delay | long | amount of time first polling is delayed after start | 0 | period | long | amount of time between polls | 5000 | file | string | sets the file or directory to poll | null (must be spec'd) | deleteFile | boolean | delete file when it is processed | true | recursive | boolean | process sub directories | true | marshaler | class | org.apache.servicemix.components.util.FileMarshaler | DefaultFileMarshaler | lockManager | class | org.apache.servicemix.locks.LockManager | SimpleLockManager | filter | class | java.io.FileFilter (optional filter) | null - no filter | scheduler | class | org.apache.servicemix.components.varscheduler.Scheduler | new Scheduler(true) | comparator | class | implementation of java.util.Comparator<File> interface | null - no ordering | archive | string | sets the directory to archive files before deleting them (available since 3.2) | null (no archiving) |
|
Sender Endpoint
A File Sender endpoint expects messages coming from the NMR, converts it to file content (using the marshaler) and write file in the given directory.
Code Block |
---|
lang | xml |
---|
title | Sender (Provider) Endpoint |
---|
|
<file:sender service="test:service"
endpoint="endpoint"
directory="file:target/pollerFiles" />
|
Info |
---|
title | Sender endpoint attributesEndpoint Attributes |
---|
borderStyle | solidbgColor='lighblue' |
---|
|
Name | Type | Description | Default |
---|
service | QName | the service name of the endpoint | required to be spec'd | endpoint | string | the endpoint name of the endpoint | required to be spec'd | directory | file | | required to be spec'd | autoCreateDirectory | boolean | | true | append | boolean | append to an existing file instead of overwriting it (3.3 or above) | false | marshaler | class | org.apache.servicemix.components.util.FileMarshaler | DefaultFileMarshaler | tempFilePrefix | string | | "servicemix-" | tempFileSuffix | string | | ".xml" |
|
...
URI
You can use the familiar file URI to communicate with files
Code Block |
---|
file:foo.xml
file://path/to/something
|
Filtering
Filtering of files to use during the polling process can be accomplished by configuring the filter property.
...
In the example above, the Apache ORO jar must be in the classpath. See: http://jakarta.apache.org/oro/Image Removed
Code Block |
---|
lang | xml |
---|
title | ServiceMix 3.2 Filter example |
---|
|
<file:poller service="test:poller" endpoint="poller"
file="file:inbox" targetService="test:service"
targetEndpoint="endpoint" period="10000" recursive="true">
<property name="filter">
<bean class="org.apache.commons.io.filefilter.WildcardFilter">
<constructor-arg value="*.csv" />
</bean>
</property>
</file:poller>
|
In the example above it uses Apache Commons IO WildcardFilter as it implements FileFilter. The Apache Commons IO jar file must be in the classpath. See: http://commons.apache.org/io/Image Removed
Comparators
You can define an implementation of the java.util.Comparator interface to specifies the process order of the files.
...