public class MongoDbMessageSource extends AbstractMessageSource<Object>
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 payoad 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.
IntegrationManagement.ManagementOverridesEXPRESSION_PARSER, loggerMETER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME| Constructor and Description |
|---|
MongoDbMessageSource(MongoDbFactory mongoDbFactory,
Expression queryExpression)
Creates an instance with the provided
MongoDbFactory and SpEL expression
which should resolve to a MongoDb 'query' string
(see https://www.mongodb.org/display/DOCS/Querying). |
MongoDbMessageSource(MongoOperations mongoTemplate,
Expression queryExpression)
Creates an instance with the provided
MongoOperations 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 |
|---|---|
protected Object |
doReceive()
Will execute a
Query returning its results as the Message payload. |
String |
getComponentType() |
protected void |
onInit() |
void |
setCollectionNameExpression(Expression collectionNameExpression)
Sets the SpEL
Expression that should resolve to a collection name
used by the Query. |
void |
setEntityClass(Class<?> entityClass)
Allows you to set the type of the entityClass that will be passed to the
MongoTemplate.find(Query, Class) or MongoTemplate.findOne(Query, Class)
method. |
void |
setExpectSingleResult(boolean expectSingleResult)
Allows you to manage which find* method to invoke on
MongoTemplate. |
void |
setMongoConverter(MongoConverter mongoConverter)
Allows you to provide a custom
MongoConverter used to assist in deserialization
data read from MongoDb. |
buildMessage, destroy, getBeanName, getComponentName, getManagedName, getManagedType, getMessageCount, getMessageCountLong, getOverrides, isCountsEnabled, isLoggingEnabled, receive, registerMetricsCaptor, reset, setBeanName, setCountsEnabled, 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, waitmessageCountpublic MongoDbMessageSource(MongoDbFactory mongoDbFactory, Expression queryExpression)
MongoDbFactory 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.mongoDbFactory - The mongodb factory.queryExpression - The query expression.public MongoDbMessageSource(MongoOperations mongoTemplate, Expression queryExpression)
MongoOperations and SpEL expression
which should resolve to a Mongo 'query' string
(see https://www.mongodb.org/display/DOCS/Querying).
It assumes that the MongoOperations is fully initialized and ready to be used.
The 'queryExpression' will be evaluated on every call to the AbstractMessageSource.receive() method.mongoTemplate - The mongo template.queryExpression - The query expression.public void setEntityClass(Class<?> entityClass)
MongoTemplate.find(Query, Class) or MongoTemplate.findOne(Query, Class)
method.
Default is DBObject.entityClass - The entity class.public void setExpectSingleResult(boolean expectSingleResult)
MongoTemplate.
Default is 'false', which means the AbstractMessageSource.receive() method will use
the MongoTemplate.find(Query, Class) method. If set to 'true',
AbstractMessageSource.receive() will use MongoTemplate.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(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(MongoConverter mongoConverter)
MongoConverter used to assist in deserialization
data read from MongoDb. Only allowed if this instance was constructed with a
MongoDbFactory.mongoConverter - The mongo converter.public String getComponentType()
protected void onInit()
onInit in class AbstractExpressionEvaluatorprotected Object doReceive()
Query returning its results as the Message payload.
The payload can be either List of elements 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
List. The collection name used in the
query will be provided in the MongoHeaders.COLLECTION_NAME header.doReceive in class AbstractMessageSource<Object>