public class ReactiveMongoDbMessageSource
extends org.springframework.integration.endpoint.AbstractMessageSource<org.reactivestreams.Publisher<?>>
implements org.springframework.context.ApplicationContextAware
MessageSource which returns
a Message with a payload which is the result of
execution of a Query. When expectSingleResult is false (default), the MongoDb
Query is executed using ReactiveMongoOperations.find(Query, Class) method which
returns a Flux.
The returned Flux will be used as the payload of the
Message returned by the AbstractMessageSource.receive()
method.
When expectSingleResult is true, the ReactiveMongoOperations.findOne(Query, Class) is
used instead, and the message payload will be a Mono
for the single object returned from the query.
| Constructor and Description |
|---|
ReactiveMongoDbMessageSource(org.springframework.data.mongodb.ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory,
org.springframework.expression.Expression queryExpression)
Create an instance with the provided
ReactiveMongoDatabaseFactory and SpEL expression
which should resolve to a MongoDb 'query' string (see https://www.mongodb.org/display/DOCS/Querying). |
ReactiveMongoDbMessageSource(org.springframework.data.mongodb.core.ReactiveMongoOperations reactiveMongoTemplate,
org.springframework.expression.Expression queryExpression)
Create an instance with the provided
ReactiveMongoOperations and SpEL expression
which should resolve to a Mongo 'query' string (see https://www.mongodb.org/display/DOCS/Querying). |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
doReceive()
Execute a
Query returning its results as the Message payload. |
java.lang.String |
getComponentType() |
protected void |
onInit() |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setCollectionNameExpression(org.springframework.expression.Expression collectionNameExpression)
Set the SpEL
Expression that should resolve to a collection name
used by the Query. |
void |
setEntityClass(java.lang.Class<?> entityClass)
Allow you to set the type of the entityClass that will be passed to the
ReactiveMongoTemplate.find(Query, Class) or ReactiveMongoTemplate.findOne(Query, Class)
method. |
void |
setExpectSingleResult(boolean expectSingleResult)
Allow you to manage which find* method to invoke on
ReactiveMongoTemplate. |
void |
setMongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter mongoConverter)
Allow you to provide a custom
MongoConverter used to assist in deserialization
data read from MongoDb. |
buildMessage, destroy, getBeanName, getComponentName, getManagedName, getManagedType, getOverrides, isLoggingEnabled, receive, registerMetricsCaptor, setBeanName, setHeaderExpressions, setLoggingEnabled, setManagedName, setManagedTypeafterPropertiesSet, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, getBeanFactory, getEvaluationContext, getEvaluationContext, getMessageBuilderFactory, setBeanFactory, setConversionServiceclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitpublic ReactiveMongoDbMessageSource(org.springframework.data.mongodb.ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory,
org.springframework.expression.Expression queryExpression)
ReactiveMongoDatabaseFactory and SpEL expression
which should resolve to a MongoDb 'query' string (see https://www.mongodb.org/display/DOCS/Querying).
The 'queryExpression' will be evaluated on every call to the AbstractMessageSource.receive() method.reactiveMongoDatabaseFactory - The reactiveMongoDatabaseFactory factory.queryExpression - The query expression.public ReactiveMongoDbMessageSource(org.springframework.data.mongodb.core.ReactiveMongoOperations reactiveMongoTemplate,
org.springframework.expression.Expression queryExpression)
ReactiveMongoOperations and SpEL expression
which should resolve to a Mongo 'query' string (see https://www.mongodb.org/display/DOCS/Querying).
It assumes that the ReactiveMongoOperations is fully initialized and ready to be used.
The 'queryExpression' will be evaluated on every call to the AbstractMessageSource.receive() method.reactiveMongoTemplate - The reactive Mongo template.queryExpression - The query expression.public void setEntityClass(java.lang.Class<?> entityClass)
ReactiveMongoTemplate.find(Query, Class) or ReactiveMongoTemplate.findOne(Query, Class)
method.
Default is DBObject.entityClass - The entity class.public void setExpectSingleResult(boolean expectSingleResult)
ReactiveMongoTemplate.
Default is 'false', which means the AbstractMessageSource.receive() method will use
the ReactiveMongoTemplate.find(Query, Class) method. If set to 'true',
AbstractMessageSource.receive() will use ReactiveMongoTemplate.findOne(Query, Class),
and the payload of the returned Message
will be the returned target Object of type
identified by entityClass instead of a List.expectSingleResult - true if a single result is expected.public void setCollectionNameExpression(org.springframework.expression.Expression collectionNameExpression)
Expression that should resolve to a collection name
used by the Query. The resulting collection name will be included
in the MongoHeaders.COLLECTION_NAME header.collectionNameExpression - The collection name expression.public void setMongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter mongoConverter)
MongoConverter used to assist in deserialization
data read from MongoDb. Only allowed if this instance was constructed with a
ReactiveMongoDatabaseFactory.mongoConverter - The mongo converter.public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic java.lang.String getComponentType()
getComponentType in interface org.springframework.integration.support.context.NamedComponentprotected void onInit()
onInit in class org.springframework.integration.util.AbstractExpressionEvaluatorpublic java.lang.Object doReceive()
Query returning its results as the Message payload.
The payload can be either Flux or
Mono of objects of type identified by entityClass,
or a single element of type identified by entityClass
based on the value of expectSingleResult attribute which defaults to 'false' resulting
Message with payload of type
Flux. The collection name used in the
query will be provided in the MongoHeaders.COLLECTION_NAME header.doReceive in class org.springframework.integration.endpoint.AbstractMessageSource<org.reactivestreams.Publisher<?>>