Files
Artem Bilan 1e6a2e1f44 GH-143: Add an update option to MongoDB Supplier (#147)
* GH-143: Add an update option to MongoDB Supplier

Fixes https://github.com/spring-cloud/stream-applications/issues/143

* * Fix Checkstyle violations
* Update `README.adoc` for `mongodb-source`
2021-02-05 15:36:03 -05:00
..

# MongoDB Supplier

This module provides a MongoDB supplier that can be reused and composed in other applications.
The `Supplier` uses the `MongoDBMessageSource` from Spring Integration.
`MongoDBSupplier` is implemented as a `java.util.function.Supplier`.
When you have use-cases such as periodical execution of querying MongoDB, based on some external trigger such as a REST endpoint call for example, then you can use this `Supplier` to query.

## Beans for injection

You can import the `MongoDBSupplierConfiguration` in the application and then inject the following bean.

`mongoDBSupplier`

You can inject it as `Supplier<Message<?>` when you are not splitting the rows.
If you are splitting the output, you need to inject this as `Supplier<Flux<Message<?>>>`.

You can use `mongoDBSupplier` as a qualifier when injecting.

Once injected, you can use the `get` method of the `Supplier` to invoke it.
In the case of splitting you get a `Flux` which you have to subscribe in your applications.

## Configuration Options

All configuration properties are prefixed with `mongodb.supplier`.

For more information on the various options available, please see link:src/main/java/org/springframework/cloud/fn/supplier/mongo/MongodbSupplierProperties.java[MongoDBSupplierProperties].

The `queryExpression` and `updateExpression` options may use Spring Data MongoDB query DSL from the `org.springframework.data.mongodb.core.query`, such as `Query` and `Update` factories respectively.
The `updateExpression` is optional and ca use an item from query result as a root evaluation object to extract some values to update from just fetched data.

## Tests

See this link:src/test/java/org/springframework/cloud/fn/supplier/mongo/MongodbSupplierApplicationTests.java[test suite] for the various ways, this supplier is used.

## Other usage

See this https://github.com/spring-cloud/stream-applications/blob/master/applications/source/mongodb-source/README.adoc[README] where this supplier is used to create a Spring Cloud Stream application where it makes a MongoDB Source.