...
Code Block |
---|
|
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mongodb-gridfs</artifactId>
<version>x.y.z</version>
<!-- use the same version as your Camel core version -->
</dependency>
|
URI format
Code Block |
---|
mongodb-gridfs:connectionBean?database=databaseName&bucket=bucketName[&moreOptions...]
|
URI format ( camel < 2.19 )
Code Block |
---|
gridfs:connectionBean?database=databaseName&bucket=bucketName[&moreOptions...] |
Endpoint options
GridFS endpoints support the following options, depending on whether they are acting like a Producer or as a Consumer (options vary based on the consumer type too).
...
Code Block |
---|
language | xml |
---|
title | Get a file from GridFS |
---|
|
<route>
<from uri="direct:start" />
<!-- using bean 'mongoBean' defined above -->
<to uri="mongodb-gridfs:mongoBean?database=${mongodb.database}&operation=findOne" />
<to uri="direct:result" />
</route> |
...
Code Block |
---|
// from("direct:count").to("mongodb-gridfs?database=tickets&operation=count");
Integer result = template.requestBodyAndHeader("direct:count", "irrelevantBody");
assertTrue("Result is not of type Long", result instanceof Integer);
|
...
Code Block |
---|
// from("direct:listAll").to("mongodb-gridfs?database=tickets&operation=listAll");
Reader result = template.requestBodyAndHeader("direct:listAll", "irrelevantBody");
filename1.txt 1252314321
filename2.txt 2897651254 |
...
Code Block |
---|
// from("direct:findOne").to("mongodb-gridfs?database=tickets&operation=findOne");
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(Exchange.FILE_NAME, "filename.txt");
InputStream result = template.requestBodyAndHeaders("direct:findOne", "irrelevantBody", headers);
|
...
Code Block |
---|
// from("direct:create").to("mongodb-gridfs?database=tickets&operation=create");
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(Exchange.FILE_NAME, "filename.txt");
InputStream stream = ... the data for the file ...
template.requestBodyAndHeaders("direct:create", stream, headers); |
...
Code Block |
---|
// from("direct:remove").to("mongodb-gridfs?database=tickets&operation=remove");
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(Exchange.FILE_NAME, "filename.txt");
template.requestBodyAndHeaders("direct:remove", "", headers); |
...
- TimeStamp - (default) when the consumer starts up, it uses the current time as the starting point. Any files currently in the grid are ignored, only files added after the consumer start are processed. After polling, the consumer updates it's timestamp with the timestamp of the newest file processed.
- PersistentTimestamp - when the consumer starts up, it queries the collection specified by the persistentTSCollection parameter for the object given by the persistentTSObject parameter to use as the starting timestamp. If the object doesn't exist, it uses the current time and creates the object. After each file processed, the timestamp in the collection is updated.
- FileAttribute - instead of timestamps, the consumer will query gridfs for files that don't have the attribute given by the fileAttributeName parameter. When the file starts to be processed by the consumer, the attribute is added to the file in the gridfs.
- TimestampAndFileAttribute - finds files that are newer than the TimeStamp and are missing the attribute. Adds the attribute to the file when processing.
- PersistentTimestampAndFileAttribute - finds files that are newer than the TimeStamp and are missing the attribute. Adds the attribute to the file when processing and updates the persistent timestamp.
Code Block |
---|
|
from("mongodb-gridfs?database=tickets&queryStrategy=FileAttribute").process(.....);
from("mongodb-gridfs?database=myData&queryStrategy=PersistentTimestamp&persistentTSCollection=CamelTimestamps&persistentTSObject=myDataTS").process(...) |
...