Class ReactiveMongoDbMessageSource
java.lang.Object
org.springframework.integration.util.AbstractExpressionEvaluator
org.springframework.integration.endpoint.AbstractMessageSource<org.reactivestreams.Publisher<?>>
org.springframework.integration.mongodb.inbound.ReactiveMongoDbMessageSource
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,MessageSource<org.reactivestreams.Publisher<?>>
,IntegrationPattern
,NamedComponent
,IntegrationInboundManagement
,IntegrationManagement
public class ReactiveMongoDbMessageSource extends AbstractMessageSource<org.reactivestreams.Publisher<?>> implements ApplicationContextAware
An instance of
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.
- Since:
- 5.3
- Author:
- David Turanski, Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields inherited from class org.springframework.integration.util.AbstractExpressionEvaluator
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
-
Constructor Summary
Constructors Constructor Description ReactiveMongoDbMessageSource(ReactiveMongoOperations reactiveMongoTemplate, Expression queryExpression)
Create an instance with the providedReactiveMongoOperations
and SpEL expression which should resolve to a Mongo 'query' string (see https://www.mongodb.org/display/DOCS/Querying).ReactiveMongoDbMessageSource(ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory, Expression queryExpression)
Create an instance with the providedReactiveMongoDatabaseFactory
and SpEL expression which should resolve to a MongoDb 'query' string (see https://www.mongodb.org/display/DOCS/Querying). -
Method Summary
Modifier and Type Method Description Object
doReceive()
Execute aQuery
returning its results as the Message payload.String
getComponentType()
protected void
onInit()
void
setApplicationContext(ApplicationContext applicationContext)
void
setCollectionNameExpression(Expression collectionNameExpression)
Set the SpELExpression
that should resolve to a collection name used by theQuery
.void
setEntityClass(Class<?> entityClass)
Allow you to set the type of the entityClass that will be passed to theReactiveMongoTemplate.find(Query, Class)
orReactiveMongoTemplate.findOne(Query, Class)
method.void
setExpectSingleResult(boolean expectSingleResult)
Allow you to manage which find* method to invoke onReactiveMongoTemplate
.void
setMongoConverter(MongoConverter mongoConverter)
Allow you to provide a customMongoConverter
used to assist in deserialization data read from MongoDb.Methods inherited from class org.springframework.integration.endpoint.AbstractMessageSource
buildMessage, destroy, getBeanName, getComponentName, getManagedName, getManagedType, getOverrides, isLoggingEnabled, receive, registerMetricsCaptor, setBeanName, setHeaderExpressions, setLoggingEnabled, setManagedName, setManagedType
Methods inherited from class org.springframework.integration.util.AbstractExpressionEvaluator
afterPropertiesSet, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, getBeanFactory, getEvaluationContext, getEvaluationContext, getMessageBuilderFactory, setBeanFactory, setConversionService
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAs
Methods inherited from interface org.springframework.integration.core.MessageSource
getIntegrationPatternType
-
Constructor Details
-
ReactiveMongoDbMessageSource
public ReactiveMongoDbMessageSource(ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory, Expression queryExpression)Create an instance with the providedReactiveMongoDatabaseFactory
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 theAbstractMessageSource.receive()
method.- Parameters:
reactiveMongoDatabaseFactory
- The reactiveMongoDatabaseFactory factory.queryExpression
- The query expression.
-
ReactiveMongoDbMessageSource
public ReactiveMongoDbMessageSource(ReactiveMongoOperations reactiveMongoTemplate, Expression queryExpression)Create an instance with the providedReactiveMongoOperations
and SpEL expression which should resolve to a Mongo 'query' string (see https://www.mongodb.org/display/DOCS/Querying). It assumes that theReactiveMongoOperations
is fully initialized and ready to be used. The 'queryExpression' will be evaluated on every call to theAbstractMessageSource.receive()
method.- Parameters:
reactiveMongoTemplate
- The reactive Mongo template.queryExpression
- The query expression.
-
-
Method Details
-
setEntityClass
Allow you to set the type of the entityClass that will be passed to theReactiveMongoTemplate.find(Query, Class)
orReactiveMongoTemplate.findOne(Query, Class)
method. Default isDBObject
.- Parameters:
entityClass
- The entity class.
-
setExpectSingleResult
public void setExpectSingleResult(boolean expectSingleResult)Allow you to manage which find* method to invoke onReactiveMongoTemplate
. Default is 'false', which means theAbstractMessageSource.receive()
method will use theReactiveMongoTemplate.find(Query, Class)
method. If set to 'true',AbstractMessageSource.receive()
will useReactiveMongoTemplate.findOne(Query, Class)
, and the payload of the returnedMessage
will be the returned target Object of type identified byentityClass
instead of a List.- Parameters:
expectSingleResult
- true if a single result is expected.
-
setCollectionNameExpression
Set the SpELExpression
that should resolve to a collection name used by theQuery
. The resulting collection name will be included in theMongoHeaders.COLLECTION_NAME
header.- Parameters:
collectionNameExpression
- The collection name expression.
-
setMongoConverter
Allow you to provide a customMongoConverter
used to assist in deserialization data read from MongoDb. Only allowed if this instance was constructed with aReactiveMongoDatabaseFactory
.- Parameters:
mongoConverter
- The mongo converter.
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
getComponentType
- Specified by:
getComponentType
in interfaceNamedComponent
-
onInit
protected void onInit()- Overrides:
onInit
in classAbstractExpressionEvaluator
-
doReceive
Execute aQuery
returning its results as the Message payload. The payload can be eitherFlux
orMono
of objects of type identified byentityClass
, or a single element of type identified byentityClass
based on the value ofexpectSingleResult
attribute which defaults to 'false' resultingMessage
with payload of typeFlux
. The collection name used in the query will be provided in theMongoHeaders.COLLECTION_NAME
header.- Specified by:
doReceive
in classAbstractMessageSource<org.reactivestreams.Publisher<?>>
- Returns:
- The value returned.
-