diff --git a/src/reference/docbook/mongodb.xml b/src/reference/docbook/mongodb.xml index 10ffdb6f16..61e324686b 100644 --- a/src/reference/docbook/mongodb.xml +++ b/src/reference/docbook/mongodb.xml @@ -112,5 +112,167 @@ MongoDbFactory as a constructor argument. + +
+ MongoDB Inbound Channel Adapter + + + The MongoDb Inbound Channel Adapter is a polling consumer that reads data + from MongoDb and sends it as a Message payload. + + + + +]]> + + + As you can see from the configuration above, you configure a MongoDb Inbound Channel Adapter using + the inbound-channel-adapter element, providing values for various attributes such as: + + + query or query-expression - a + JSON query (see MongoDb Querying) + + + entity-class - the type of the payload object; if not supplied, a + com.mongodb.DBObject will be returned. + + + collection-name or collection-name-expression - + Identifies the name of the MongoDb collection to use. + + + mongodb-factory - + reference to an instance of org.springframework.data.mongodb.MongoDbFactory + + + mongo-template - + reference to an instance of org.springframework.data.mongodb.core.MongoTemplate + + + + and other attributes that are common across all other inbound adapters (e.g., 'channel'). + + + You cannot set both mongo-template and mongodb-factory. + + + The example above is relatively simple and static since it has a literal value for the query and uses + the default name for a collection. Sometimes you may need to change those values at runtime, based on some condition. + To do that, simply use their -expression equivalents (query-expression and + collection-name-expression) where the provided expression can be any valid SpEL expression. + + + Also, you may wish to do some post-processing to the successfully processed data that was read from the MongoDb. + For example; you may want to move or remove a document after its been processed. + You can do this using Transaction Synchronization feature that was added with Spring Integration 2.2. + + + + + + + + + + + + + +]]> + +){ + List documents = (List) target; + for (Object document : documents) { + mongoOperations.remove(new BasicQuery(JSON.serialize(document)), collectionName); + } + } + } +}]]> + + As you can see from the above, all you need to do is declare your poller to be transactional with a transactional element. + This element can reference a real transaction manager (for example if some other part of your flow invokes JDBC). + If you don't have a 'real' transaction, you can use a + org.springframework.integration.transaction.PseudoTransactionManager which is an implementation + of the Spring's PlatformTransactionManager and enables the use of the transaction synchronization + features of the mongo adapter when there is no actual transaction. + + + This does NOT make MongoDB itself transactional, it simply allows the synchronization of actions to be taken before/after success (commit) + or after failure (rollback). + + + Once your poller is transactional all you need to do is set an instance of the + org.springframework.integration.transaction.TransactionSynchronizationFactory on the transactional element. + TransactionSynchronizationFactory will create an instance of the TransactioinSynchronization. + For your convenience, we've exposed a default SpEL-based TransactionSynchronizationFactory which allows + you to configure SpEL expressions, with their execution being coordinated (synchronized) with a transaction. + Expressions for before-commit, after-commit, and after-rollback are supported, together with a channel for each where the + evaluation result (if any) will be sent. For each sub-element you can specify expression and/or channel + attributes. If only the channel attribute is present the received Message will be sent there as part of the particular + synchronization scenario. If only the expression attribute is present and the result of an expression is a non-Null + value, a Message with the result as the payload will be generated and sent to a default channel (NullChannel) and will appear in the + logs (DEBUG). If you want the evaluation result to go to a specific channel add a channel attribute. If the result of an + expression is null or void, no Message will be generated. + + + For more information about transaction synchronization, see . + +
+ +
+ MongoDB Outbound Channel Adapter + + + The MongoDb Outbound Channel Adapter allows you to write the Message payload to a MongoDb document store + + + ]]> + + + As you can see from the configuration above, you configure a MongoDb Outbound Channel Adapter using + the outbound-channel-adapter element while also providing values for various attributes such as: + + + collection-name or collection-name-expression - + Identifies the name of the MongoDb collection to use. + + + mongo-converter - + reference to an instance of org.springframework.data.mongodb.core.convert.MongoConverter to assist with + converting a raw java object to a JSON document representation + + + mongodb-factory - + reference to an instance of org.springframework.data.mongodb.MongoDbFactory + + + mongo-template - + reference to an instance of org.springframework.data.mongodb.core.MongoTemplate + (NOTE: you can not have both mongo-template and mongodb-factory set) + + + and other attributes that are common across all other inbound adapters (e.g., 'channel'). + + + The example above is relatively simple and static since it has a literal value for the collection-name. + Sometimes you may need to change this value at runtime based on some condition. + To do that, simply use collection-name-expression + where the provided expression can be any valid SpEL expression. + +
\ No newline at end of file