Class MongoDbMessageSource
java.lang.Object
org.springframework.integration.util.AbstractExpressionEvaluator
org.springframework.integration.endpoint.AbstractMessageSource<T>
org.springframework.integration.mongodb.inbound.AbstractMongoDbMessageSource<java.lang.Object>
org.springframework.integration.mongodb.inbound.MongoDbMessageSource
- 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<java.lang.Object>,org.springframework.integration.IntegrationPattern,org.springframework.integration.support.context.NamedComponent,org.springframework.integration.support.management.IntegrationInboundManagement,org.springframework.integration.support.management.IntegrationManagement
public class MongoDbMessageSource extends AbstractMongoDbMessageSource<java.lang.Object>
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 MongoOperations.find(Query, Class) method which
returns a List. The returned List will be used as the payload of the
Message returned by the {AbstractMessageSource.receive()
method. An empty List is treated as null, thus resulting in no
Message returned by the {AbstractMessageSource.receive()
method.
When expectSingleResult is true, the MongoOperations.findOne(Query, Class) is
used instead, and the message payload will be the single object returned from the
query.
- Since:
- 2.2
-
Nested Class Summary
-
Field Summary
Fields inherited from class org.springframework.integration.mongodb.inbound.AbstractMongoDbMessageSource
queryExpression -
Constructor Summary
Constructors Constructor Description MongoDbMessageSource(org.springframework.data.mongodb.core.MongoOperations mongoTemplate, org.springframework.expression.Expression queryExpression)Create an instance with the providedMongoOperationsand SpEL expression which should resolve to a Mongo 'query' string (see https://www.mongodb.org/display/DOCS/Querying).MongoDbMessageSource(org.springframework.data.mongodb.MongoDatabaseFactory mongoDbFactory, org.springframework.expression.Expression queryExpression)Create an instance with the providedMongoDatabaseFactoryand 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 protected java.lang.ObjectdoReceive()Will execute aQueryreturning its results as the Message payload.java.lang.StringgetComponentType()protected voidonInit()Methods inherited from class org.springframework.integration.mongodb.inbound.AbstractMongoDbMessageSource
evaluateCollectionNameExpression, evaluateQueryExpression, evaluateUpdateExpression, getApplicationContext, getByIdInQuery, getCollectionNameExpression, getEntityClass, getMongoConverter, getUpdateExpression, idForEntity, isExpectSingleResult, isInitialized, setApplicationContext, setCollectionNameExpression, setEntityClass, setExpectSingleResult, setInitialized, setMongoConverter, setUpdateExpressionMethods 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
-
MongoDbMessageSource
public MongoDbMessageSource(org.springframework.data.mongodb.MongoDatabaseFactory mongoDbFactory, org.springframework.expression.Expression queryExpression)Create an instance with the providedMongoDatabaseFactoryand 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:
mongoDbFactory- The mongodb factory.queryExpression- The query expression.
-
MongoDbMessageSource
public MongoDbMessageSource(org.springframework.data.mongodb.core.MongoOperations mongoTemplate, org.springframework.expression.Expression queryExpression)Create an instance with the providedMongoOperationsand SpEL expression which should resolve to a Mongo 'query' string (see https://www.mongodb.org/display/DOCS/Querying). It assumes that theMongoOperationsis fully initialized and ready to be used. The 'queryExpression' will be evaluated on every call to theAbstractMessageSource.receive()method.- Parameters:
mongoTemplate- The mongo template.queryExpression- The query expression.
-
-
Method Details
-
getComponentType
public java.lang.String getComponentType() -
onInit
protected void onInit()- Overrides:
onInitin classAbstractMongoDbMessageSource<java.lang.Object>
-
doReceive
protected java.lang.Object doReceive()Will execute aQueryreturning its results as the Message payload. The payload can be eitherListof elements of objects of type identified byAbstractMongoDbMessageSource.getEntityClass(), or a single element of type identified byAbstractMongoDbMessageSource.getEntityClass()based on the value ofAbstractMongoDbMessageSource.isExpectSingleResult()attribute which defaults to 'false' resultingMessagewith payload of typeList. The collection name used in the query will be provided in theMongoHeaders.COLLECTION_NAMEheader.- Specified by:
doReceivein classorg.springframework.integration.endpoint.AbstractMessageSource<java.lang.Object>
-