Class MongoDbSender

All Implemented Interfaces:
FrankElement, HasApplicationContext, HasName, HasPhysicalDestination, IConfigurable, IScopeProvider, ISender, ISenderWithParameters, IWithParameters, NameAware, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle

public class MongoDbSender extends AbstractSenderWithParameters implements HasPhysicalDestination
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 attribute collection, filter Filter. Can contain references to parameters between '?{' and '}'. Overrides attribute filter, limit Limit to number of results returned. A value of 0 means 'no limit'. Overrides attribute limit
  • Field Details

  • Constructor Details

    • MongoDbSender

      public MongoDbSender()
  • Method Details

    • configure

      public void configure() throws ConfigurationException
      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 the configure() or open() method, to improve performance.
      Specified by:
      configure in interface IConfigurable
      Specified by:
      configure in interface ISender
      Overrides:
      configure in class AbstractSenderWithParameters
      Throws:
      ConfigurationException - in case it was not able to configure the component.
    • 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 the sendMessage() method.
      Specified by:
      start in interface ISender
      Specified by:
      start in interface org.springframework.context.Lifecycle
      Overrides:
      start in class AbstractSender
    • stop

      public void stop()
      Description copied from interface: ISender
      Stop/close the sender and deallocate resources.
      Specified by:
      stop in interface ISender
      Specified by:
      stop in interface org.springframework.context.Lifecycle
      Overrides:
      stop in class AbstractSender
    • 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 the configure() method is called.

      The following table shows the difference between synchronous and a-synchronous senders:

       synchronousa-synchronous
      ISender.isSynchronous() returnstruefalse
      return value of sendMessage() isthe reply-messagethe messageId of the message sent
      the correlationID specified with sendMessage()may be ignoredis sent with the message
      a {link TimeOutException}may be thrown if a timeout occurs waiting for a replyshould 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 interface ISender
      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

      protected org.bson.Document getDocument(Message message) throws IOException
      Throws:
      IOException
    • getDocument

      protected org.bson.Document getDocument(String message)
    • getDocuments

      protected List<org.bson.Document> getDocuments(Message message) throws IOException
      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

      protected int getLimit(ParameterValueList pvl)
    • getPhysicalDestinationName

      public String getPhysicalDestinationName()
      Specified by:
      getPhysicalDestinationName in interface HasPhysicalDestination
    • setDatasourceName

      public void setDatasourceName(String datasourceName)
      The MongoDB datasource
      Default value
      "mongodb.datasource.default"
    • setDatabase

      public void setDatabase(String database)
      Database to connect to. Can be overridden by parameter "database"
    • setCollection

      public void setCollection(String collection)
      Collection to act upon. Can be overridden by parameter "collection"
    • setAction

      public void setAction(MongoDbSender.MongoAction action)
      Action
    • setFilter

      public void setFilter(String filter)
      Filter. Can contain references to parameters between "?{" and "}". Can be overridden by parameter "filter"
    • 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

      public void setOutputFormat(DocumentFormat outputFormat)
      OutputFormat
      Default value
      JSON
    • setPrettyPrint

      public void setPrettyPrint(boolean prettyPrint)
      Format the output in easy legible way (currently only for XML)
    • getDomain

      public String getDomain()
      Specified by:
      getDomain in interface HasPhysicalDestination
    • getDatasourceName

      public String getDatasourceName()
    • getDatabase

      public String getDatabase()
    • getCollection

      public String getCollection()
    • getAction

      public MongoDbSender.MongoAction getAction()
    • getFilter

      public String getFilter()
    • getLimit

      public int getLimit()
    • isCountOnly

      public boolean isCountOnly()
    • getOutputFormat

      public DocumentFormat getOutputFormat()
    • isPrettyPrint

      public boolean isPrettyPrint()
    • setMongoClientFactory

      public void setMongoClientFactory(IMongoClientFactory mongoClientFactory)
    • getMongoClientFactory

      public IMongoClientFactory getMongoClientFactory()