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:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware,org.springframework.integration.core.MessageSource<org.reactivestreams.Publisher<?>>,org.springframework.integration.IntegrationPattern,org.springframework.integration.support.context.NamedComponent,org.springframework.integration.support.management.IntegrationInboundManagement,org.springframework.integration.support.management.IntegrationManagement
public class ReactiveMongoDbMessageSource
extends org.springframework.integration.endpoint.AbstractMessageSource<org.reactivestreams.Publisher<?>>
implements org.springframework.context.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
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ReactiveMongoDbMessageSource(org.springframework.data.mongodb.core.ReactiveMongoOperations reactiveMongoTemplate, org.springframework.expression.Expression queryExpression)Create an instance with the providedReactiveMongoOperationsand SpEL expression which should resolve to a Mongo 'query' string (see https://www.mongodb.org/display/DOCS/Querying).ReactiveMongoDbMessageSource(org.springframework.data.mongodb.ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory, org.springframework.expression.Expression queryExpression)Create an instance with the providedReactiveMongoDatabaseFactoryand 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 java.lang.ObjectdoReceive()Execute aQueryreturning its results as the Message payload.java.lang.StringgetComponentType()protected voidonInit()voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)voidsetCollectionNameExpression(org.springframework.expression.Expression collectionNameExpression)Set the SpELExpressionthat should resolve to a collection name used by theQuery.voidsetEntityClass(java.lang.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.voidsetExpectSingleResult(boolean expectSingleResult)Allow you to manage which find* method to invoke onReactiveMongoTemplate.voidsetMongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter mongoConverter)Allow you to provide a customMongoConverterused 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, setManagedTypeMethods inherited from class org.springframework.integration.util.AbstractExpressionEvaluator
afterPropertiesSet, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, evaluateExpression, getBeanFactory, getEvaluationContext, getEvaluationContext, getMessageBuilderFactory, setBeanFactory, setConversionServiceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
ReactiveMongoDbMessageSource
public ReactiveMongoDbMessageSource(org.springframework.data.mongodb.ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory, org.springframework.expression.Expression queryExpression)Create an instance with the providedReactiveMongoDatabaseFactoryand 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(org.springframework.data.mongodb.core.ReactiveMongoOperations reactiveMongoTemplate, org.springframework.expression.Expression queryExpression)Create an instance with the providedReactiveMongoOperationsand SpEL expression which should resolve to a Mongo 'query' string (see https://www.mongodb.org/display/DOCS/Querying). It assumes that theReactiveMongoOperationsis 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
public void setEntityClass(java.lang.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. 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 returnedMessagewill be the returned target Object of type identified byentityClassinstead of a List.- Parameters:
expectSingleResult- true if a single result is expected.
-
setCollectionNameExpression
public void setCollectionNameExpression(org.springframework.expression.Expression collectionNameExpression)Set the SpELExpressionthat should resolve to a collection name used by theQuery. The resulting collection name will be included in theMongoHeaders.COLLECTION_NAMEheader.- Parameters:
collectionNameExpression- The collection name expression.
-
setMongoConverter
public void setMongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter mongoConverter)Allow you to provide a customMongoConverterused to assist in deserialization data read from MongoDb. Only allowed if this instance was constructed with aReactiveMongoDatabaseFactory.- Parameters:
mongoConverter- The mongo converter.
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
getComponentType
public java.lang.String getComponentType()- Specified by:
getComponentTypein interfaceorg.springframework.integration.support.context.NamedComponent
-
onInit
protected void onInit()- Overrides:
onInitin classorg.springframework.integration.util.AbstractExpressionEvaluator
-
doReceive
public java.lang.Object doReceive()Execute aQueryreturning its results as the Message payload. The payload can be eitherFluxorMonoof objects of type identified byentityClass, or a single element of type identified byentityClassbased on the value ofexpectSingleResultattribute which defaults to 'false' resultingMessagewith payload of typeFlux. The collection name used in the query will be provided in theMongoHeaders.COLLECTION_NAMEheader.- Specified by:
doReceivein classorg.springframework.integration.endpoint.AbstractMessageSource<org.reactivestreams.Publisher<?>>
-