Package org.frankframework.mongodb
Class MongoDbSender
java.lang.Object
org.frankframework.senders.AbstractSender
org.frankframework.senders.AbstractSenderWithParameters
org.frankframework.mongodb.MongoDbSender
- All Implemented Interfaces:
HasPhysicalDestination
,IConfigurable
,IConfigurationAware
,INamedObject
,IScopeProvider
,ISender
,ISenderWithParameters
,IWithParameters
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
Sender to perform action on a MongoDB database.
- Author:
- Gerrit van Brakel
- Specific parameters
- database Database to connect to. Overrides attribute
database
, collection Collection to act upon. Overrides attributecollection
, filter Filter. Can contain references to parameters between '?{' and '}'. Overrides attributefilter
, limit Limit to number of results returned. A value of 0 means 'no limit'. Overrides attributelimit
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class org.frankframework.senders.AbstractSenderWithParameters
parameterNamesMustBeUnique, paramList
Fields inherited from class org.frankframework.senders.AbstractSender
log
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addOptionalValue
(ObjectBuilder builder, String name, org.bson.BsonValue bsonValue) void
configure()
is called once at startup of the framework in the configure method of the owner of this sender.protected com.mongodb.client.MongoCollection<org.bson.Document>
getCollection
(com.mongodb.client.MongoDatabase mongoDatabase, ParameterValueList pvl) protected com.mongodb.client.MongoDatabase
protected org.bson.Document
getDocument
(String message) protected org.bson.Document
getDocument
(Message message) protected List<org.bson.Document>
getDocuments
(Message message) protected org.bson.Document
getFilter
(ParameterValueList pvl, Message message) int
getLimit()
protected int
boolean
boolean
protected void
renderResult
(com.mongodb.client.FindIterable<org.bson.Document> findResults, MessageBuilder messageBuilder) protected void
renderResult
(com.mongodb.client.result.DeleteResult deleteResult, MessageBuilder messageBuilder) protected void
renderResult
(com.mongodb.client.result.InsertManyResult insertManyResult, MessageBuilder messageBuilder) protected void
renderResult
(com.mongodb.client.result.InsertOneResult insertOneResult, MessageBuilder messageBuilder) protected void
renderResult
(com.mongodb.client.result.UpdateResult updateResult, MessageBuilder messageBuilder) protected void
renderResult
(org.bson.Document findResult, MessageBuilder messageBuilder) sendMessage
(Message message, PipeLineSession session) Send a message to some destination (as configured in the Sender object).void
setAction
(MongoDbSender.MongoAction action) Actionvoid
setCollection
(String collection) Collection to act upon.void
setCountOnly
(boolean countOnly) Only for find operation: return only the count and not the full document(s)void
setDatabase
(String database) Database to connect to.void
setDatasourceName
(String datasourceName) The MongoDB datasourcevoid
Filter.void
setLimit
(int limit) Limit to number of results returned.void
setMongoClientFactory
(IMongoClientFactory mongoClientFactory) void
setOutputFormat
(DocumentFormat outputFormat) OutputFormatvoid
setPrettyPrint
(boolean prettyPrint) Format the output in easy legible way (currently only for XML)void
start()
This method will be called to start the sender.void
stop()
Stop/close the sender and deallocate resources.Methods inherited from class org.frankframework.senders.AbstractSenderWithParameters
addParameter, checkStringAttributeOrParameter, consumesSessionVariable, getParameterList, getParameterOverriddenAttributeValue, getParameterOverriddenAttributeValue, getParameterValueList
Methods inherited from class org.frankframework.senders.AbstractSender
createBean, getApplicationContext, getConfigurationClassLoader, getLogPrefix, getName, setApplicationContext, setName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContext
Methods inherited from interface org.frankframework.core.IConfigurationAware
getApplicationContext, getName
Methods inherited from interface org.frankframework.core.INamedObject
getName, setName
Methods inherited from interface org.frankframework.core.IScopeProvider
getConfigurationClassLoader
Methods inherited from interface org.frankframework.core.ISender
isSynchronous, sendMessageOrThrow
-
Field Details
-
PARAM_DATABASE
- See Also:
-
PARAM_COLLECTION
- See Also:
-
PARAM_FILTER
- See Also:
-
PARAM_LIMIT
- See Also:
-
NAMED_PARAM_START
- See Also:
-
NAMED_PARAM_END
- See Also:
-
-
Constructor Details
-
MongoDbSender
public MongoDbSender()
-
-
Method Details
-
configure
Description copied from interface:ISender
configure()
is called once at startup of the framework in the configure method of the owner of this sender. Purpose of this method is to check whether the static configuration of the sender is correct. As much as possible class-instantiating should take place in theconfigure()
oropen()
method, to improve performance.- Specified by:
configure
in interfaceIConfigurable
- Specified by:
configure
in interfaceISender
- Overrides:
configure
in classAbstractSenderWithParameters
- Throws:
ConfigurationException
-
start
public void start()Description copied from interface:ISender
This method will be called to start the sender. After this method is called the sendMessage method may be called. Purpose of this method is to reduce creating connections to databases etc. in thesendMessage()
method.- Specified by:
start
in interfaceISender
- Overrides:
start
in classAbstractSender
-
stop
public void stop()Description copied from interface:ISender
Stop/close the sender and deallocate resources.- Specified by:
stop
in interfaceISender
- Overrides:
stop
in classAbstractSender
-
sendMessage
@Nonnull public SenderResult sendMessage(@Nonnull Message message, @Nonnull PipeLineSession session) throws SenderException, TimeoutException Description copied from interface:ISender
Send a message to some destination (as configured in the Sender object). This method may only be called after theconfigure()
method is called.The following table shows the difference between synchronous and a-synchronous senders:
synchronous a-synchronous ISender.isSynchronous()
returnstrue
false
return value of sendMessage()
isthe reply-message the messageId of the message sent the correlationID specified with sendMessage()
may be ignored is sent with the message a {link TimeOutException} may be thrown if a timeout occurs waiting for a reply should not be expected Multiple objects may try to call this method at the same time, from different threads. Implementations of this method should therefore be thread-safe, or
synchronized
.- Specified by:
sendMessage
in interfaceISender
- Throws:
SenderException
TimeoutException
-
renderResult
protected void renderResult(com.mongodb.client.result.InsertOneResult insertOneResult, MessageBuilder messageBuilder) throws SAXException - Throws:
SAXException
-
renderResult
protected void renderResult(com.mongodb.client.result.InsertManyResult insertManyResult, MessageBuilder messageBuilder) throws SAXException - Throws:
SAXException
-
renderResult
protected void renderResult(org.bson.Document findResult, MessageBuilder messageBuilder) throws SAXException - Throws:
SAXException
-
renderResult
protected void renderResult(com.mongodb.client.FindIterable<org.bson.Document> findResults, MessageBuilder messageBuilder) throws IOException, SAXException - Throws:
IOException
SAXException
-
renderResult
protected void renderResult(com.mongodb.client.result.UpdateResult updateResult, MessageBuilder messageBuilder) throws SAXException - Throws:
SAXException
-
renderResult
protected void renderResult(com.mongodb.client.result.DeleteResult deleteResult, MessageBuilder messageBuilder) throws SAXException - Throws:
SAXException
-
addOptionalValue
protected void addOptionalValue(ObjectBuilder builder, String name, org.bson.BsonValue bsonValue) throws SAXException - Throws:
SAXException
-
getDocument
- Throws:
IOException
-
getDocument
-
getDocuments
- Throws:
IOException
-
getDatabase
protected com.mongodb.client.MongoDatabase getDatabase(ParameterValueList pvl) throws SenderException - Throws:
SenderException
-
getCollection
protected com.mongodb.client.MongoCollection<org.bson.Document> getCollection(com.mongodb.client.MongoDatabase mongoDatabase, ParameterValueList pvl) throws SenderException - Throws:
SenderException
-
getFilter
protected org.bson.Document getFilter(ParameterValueList pvl, Message message) throws IOException, IllegalArgumentException - Throws:
IOException
IllegalArgumentException
-
getLimit
-
getPhysicalDestinationName
- Specified by:
getPhysicalDestinationName
in interfaceHasPhysicalDestination
-
setDatasourceName
The MongoDB datasource- Default value
- "mongodb.datasource.default"
-
setDatabase
Database to connect to. Can be overridden by parameter "database" -
setCollection
Collection to act upon. Can be overridden by parameter "collection" -
setAction
Action -
setFilter
-
setLimit
public void setLimit(int limit) Limit to number of results returned. A value of 0 means 'no limit'. Can be overridden by parameter "limit".- Default value
- 0
-
setCountOnly
public void setCountOnly(boolean countOnly) Only for find operation: return only the count and not the full document(s)- Default value
- false
-
setOutputFormat
OutputFormat- Default value
- JSON
-
setPrettyPrint
public void setPrettyPrint(boolean prettyPrint) Format the output in easy legible way (currently only for XML) -
getDomain
- Specified by:
getDomain
in interfaceHasPhysicalDestination
-
getDatasourceName
-
getDatabase
-
getCollection
-
getAction
-
getFilter
-
getLimit
public int getLimit() -
isCountOnly
public boolean isCountOnly() -
getOutputFormat
-
isPrettyPrint
public boolean isPrettyPrint() -
setMongoClientFactory
-
getMongoClientFactory
-