Class MongoDbEndpoint

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.CamelContextAware, org.apache.camel.Endpoint, org.apache.camel.IsSingleton, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.HasId, org.apache.camel.StatefulService, org.apache.camel.SuspendableService

    @UriEndpoint(firstVersion="2.19.0",
                 scheme="mongodb",
                 title="MongoDB",
                 syntax="mongodb:connectionBean",
                 category={DATABASE,NOSQL},
                 headersClass=MongoDbConstants.class)
    public class MongoDbEndpoint
    extends org.apache.camel.support.DefaultEndpoint
    Perform operations on MongoDB documents and collections.
    • Constructor Detail

      • MongoDbEndpoint

        public MongoDbEndpoint()
    • Method Detail

      • createProducer

        public org.apache.camel.Producer createProducer()
      • createConsumer

        public org.apache.camel.Consumer createConsumer​(org.apache.camel.Processor processor)
                                                 throws Exception
        Throws:
        Exception
      • ensureIndex

        public void ensureIndex​(com.mongodb.client.MongoCollection<org.bson.Document> aCollection,
                                List<org.bson.conversions.Bson> dynamicIndex)
        Add Index
        Parameters:
        aCollection -
      • createIndex

        public List<org.bson.conversions.Bson> createIndex()
        Create technical list index
        Returns:
        technical list index
      • doStart

        protected void doStart()
                        throws Exception
        Overrides:
        doStart in class org.apache.camel.support.DefaultEndpoint
        Throws:
        Exception
      • getConnectionBean

        public String getConnectionBean()
      • setConnectionBean

        public void setConnectionBean​(String connectionBean)
        Name of MongoClient to use.
      • setCollection

        public void setCollection​(String collection)
        Sets the name of the MongoDB collection to bind to this endpoint
        Parameters:
        collection - collection name
      • getCollection

        public String getCollection()
      • setCollectionIndex

        public void setCollectionIndex​(String collectionIndex)
        Sets the collection index (JSON FORMAT : { "field1" : order1, "field2" : order2})
      • getCollectionIndex

        public String getCollectionIndex()
      • setOperation

        public void setOperation​(MongoDbOperation operation)
        Sets the operation this endpoint will execute against MongoDB.
      • setDatabase

        public void setDatabase​(String database)
        Sets the name of the MongoDB database to target
        Parameters:
        database - name of the MongoDB database
      • getDatabase

        public String getDatabase()
      • setCreateCollection

        public void setCreateCollection​(boolean createCollection)
        Create collection during initialisation if it doesn't exist. Default is true.
        Parameters:
        createCollection - true or false
      • isCreateCollection

        public boolean isCreateCollection()
      • setMongoConnection

        public void setMongoConnection​(com.mongodb.client.MongoClient mongoConnection)
        Sets the Mongo instance that represents the backing connection
        Parameters:
        mongoConnection - the connection to the database
      • getMongoConnection

        public com.mongodb.client.MongoClient getMongoConnection()
      • setDynamicity

        public void setDynamicity​(boolean dynamicity)
        Sets whether this endpoint will attempt to dynamically resolve the target database and collection from the incoming Exchange properties. Can be used to override at runtime the database and collection specified on the otherwise static endpoint URI. It is disabled by default to boost performance. Enabling it will take a minimal performance hit.
        Parameters:
        dynamicity - true or false indicated whether target database and collection should be calculated dynamically based on Exchange properties.
        See Also:
        MongoDbConstants.DATABASE, MongoDbConstants.COLLECTION
      • isDynamicity

        public boolean isDynamicity()
      • setDbConsumerType

        public void setDbConsumerType​(String dbConsumerType)
                               throws CamelMongoDbException
        Reserved for future use, when more consumer types are supported.
        Parameters:
        dbConsumerType - key of the consumer type
        Throws:
        CamelMongoDbException - if consumer type is not supported
      • getConsumerType

        public String getConsumerType()
      • setConsumerType

        public void setConsumerType​(String consumerType)
        Consumer type.
      • getTailTrackDb

        public String getTailTrackDb()
      • setTailTrackDb

        public void setTailTrackDb​(String tailTrackDb)
        Indicates what database the tail tracking mechanism will persist to. If not specified, the current database will be picked by default. Dynamicity will not be taken into account even if enabled, i.e. the tail tracking database will not vary past endpoint initialisation.
        Parameters:
        tailTrackDb - database name
      • getTailTrackCollection

        public String getTailTrackCollection()
      • setTailTrackCollection

        public void setTailTrackCollection​(String tailTrackCollection)
        Collection where tail tracking information will be persisted. If not specified, MongoDbTailTrackingConfig.DEFAULT_COLLECTION will be used by default.
        Parameters:
        tailTrackCollection - collection name
      • getTailTrackField

        public String getTailTrackField()
      • setTailTrackField

        public void setTailTrackField​(String tailTrackField)
        Field where the last tracked value will be placed. If not specified, MongoDbTailTrackingConfig.DEFAULT_FIELD will be used by default.
        Parameters:
        tailTrackField - field name
      • setPersistentTailTracking

        public void setPersistentTailTracking​(boolean persistentTailTracking)
        Enable persistent tail tracking, which is a mechanism to keep track of the last consumed message across system restarts. The next time the system is up, the endpoint will recover the cursor from the point where it last stopped slurping records.
        Parameters:
        persistentTailTracking - true or false
      • isPersistentTailTracking

        public boolean isPersistentTailTracking()
      • setTailTrackIncreasingField

        public void setTailTrackIncreasingField​(String tailTrackIncreasingField)
        Correlation field in the incoming record which is of increasing nature and will be used to position the tailing cursor every time it is generated. The cursor will be (re)created with a query of type: tailTrackIncreasingField greater than lastValue (possibly recovered from persistent tail tracking). Can be of type Integer, Date, String, etc. NOTE: No support for dot notation at the current time, so the field should be at the top level of the document.
        Parameters:
        tailTrackIncreasingField -
      • getTailTrackIncreasingField

        public String getTailTrackIncreasingField()
      • setCursorRegenerationDelay

        public void setCursorRegenerationDelay​(long cursorRegenerationDelay)
        MongoDB tailable cursors will block until new data arrives. If no new data is inserted, after some time the cursor will be automatically freed and closed by the MongoDB server. The client is expected to regenerate the cursor if needed. This value specifies the time to wait before attempting to fetch a new cursor, and if the attempt fails, how long before the next attempt is made. Default value is 1000ms.
        Parameters:
        cursorRegenerationDelay - delay specified in milliseconds
      • getCursorRegenerationDelay

        public long getCursorRegenerationDelay()
      • setPersistentId

        public void setPersistentId​(String persistentId)
        One tail tracking collection can host many trackers for several tailable consumers. To keep them separate, each tracker should have its own unique persistentId.
        Parameters:
        persistentId - the value of the persistent ID to use for this tailable consumer
      • getPersistentId

        public String getPersistentId()
      • isWriteResultAsHeader

        public boolean isWriteResultAsHeader()
      • setWriteResultAsHeader

        public void setWriteResultAsHeader​(boolean writeResultAsHeader)
        In write operations, it determines whether instead of returning WriteResult as the body of the OUT message, we transfer the IN message to the OUT and attach the WriteResult as a header.
        Parameters:
        writeResultAsHeader - flag to indicate if this option is enabled
      • setOutputType

        public void setOutputType​(MongoDbOutputType outputType)
        Convert the output of the producer to the selected type : DocumentList Document or MongoIterable. DocumentList or MongoIterable applies to findAll and aggregate. Document applies to all other operations.
        Parameters:
        outputType -
      • getMongoDatabase

        public com.mongodb.client.MongoDatabase getMongoDatabase()
      • getMongoCollection

        public com.mongodb.client.MongoCollection<org.bson.Document> getMongoCollection()
      • getStreamFilter

        public String getStreamFilter()
      • setStreamFilter

        public void setStreamFilter​(String streamFilter)
        Filter condition for change streams consumer.
      • setWriteConcern

        public void setWriteConcern​(String writeConcern)
        Configure the connection bean with the level of acknowledgment requested from MongoDB for write operations to a standalone mongod, replicaset or cluster. Possible values are ACKNOWLEDGED, W1, W2, W3, UNACKNOWLEDGED, JOURNALED or MAJORITY.
        Parameters:
        writeConcern -
      • getWriteConcern

        public String getWriteConcern()
      • getWriteConcernBean

        public com.mongodb.WriteConcern getWriteConcernBean()
      • setReadPreference

        public void setReadPreference​(String readPreference)
        Configure how MongoDB clients route read operations to the members of a replica set. Possible values are PRIMARY, PRIMARY_PREFERRED, SECONDARY, SECONDARY_PREFERRED or NEAREST
        Parameters:
        readPreference -
      • getReadPreference

        public String getReadPreference()
      • getReadPreferenceBean

        public com.mongodb.ReadPreference getReadPreferenceBean()
      • getUsername

        public String getUsername()
      • setUsername

        public void setUsername​(String username)
        Username for mongodb connection
        Parameters:
        username -
      • getPassword

        public String getPassword()
      • setPassword

        public void setPassword​(String password)
        User password for mongodb connection
        Parameters:
        password -
      • getHosts

        public String getHosts()
      • setHosts

        public void setHosts​(String hosts)
        Host address of mongodb server in `[host]:[port]` format. It's possible also use more than one address, as comma separated list of hosts: `[host1]:[port1],[host2]:[port2]`. If the hosts parameter is specified, the provided connectionBean is ignored.
        Parameters:
        hosts -
      • getAuthSource

        public String getAuthSource()
      • setAuthSource

        public void setAuthSource​(String authSource)
        The database name associated with the user's credentials.
        Parameters:
        authSource -