Modifier and Type | Method and Description |
---|---|
static <T> MongoSinkBuilder<T> |
builder(String name,
Class<T> itemClass,
DataLinkRef dataLinkRef)
Returns a builder object that offers a step-by-step fluent API to build
a custom MongoDB
Sink for the Pipeline API. |
static <T> MongoSinkBuilder<T> |
builder(String name,
Class<T> itemClass,
SupplierEx<com.mongodb.client.MongoClient> clientSupplier)
Returns a builder object that offers a step-by-step fluent API to build
a custom MongoDB
Sink for the Pipeline API. |
static Sink<org.bson.Document> |
mongodb(String name,
DataLinkRef dataLinkRef,
String database,
String collection)
|
static Sink<org.bson.Document> |
mongodb(String name,
String connectionString,
String database,
String collection)
|
@Beta public static <T> MongoSinkBuilder<T> builder(@Nonnull String name, @Nonnull Class<T> itemClass, @Nonnull SupplierEx<com.mongodb.client.MongoClient> clientSupplier)
Sink
for the Pipeline API.
The sink inserts or replaces the items it receives to specified collection using
MongoCollection.bulkWrite(java.util.List<? extends com.mongodb.client.model.WriteModel<? extends TDocument>>)
.
All operations are done within transaction if processing guarantee
of the job is ProcessingGuarantee.EXACTLY_ONCE
.
All writes are done using default MongoDB codecs with POJO class codec added.
Example usage:
Sink<Document> mongoSink =
MongoSinks.builder(
"stream-sink",
Document.class,
() -> MongoClients.create("mongodb://127.0.0.1:27017")
)
.into("myDatabase", "myCollection")
.identifyDocumentBy("_id", doc -> doc.get("_id"))
.build()
);
Pipeline p = Pipeline.create();
(...)
someStage.writeTo(mongoSink);
T
- type of the items the sink acceptsname
- name of the sinkclientSupplier
- MongoDB client supplieritemClass
- type of document that will be saved@Beta public static <T> MongoSinkBuilder<T> builder(@Nonnull String name, @Nonnull Class<T> itemClass, @Nonnull DataLinkRef dataLinkRef)
Sink
for the Pipeline API.
The sink inserts or replaces the items it receives to specified collection using
MongoCollection.bulkWrite(java.util.List<? extends com.mongodb.client.model.WriteModel<? extends TDocument>>)
.
All operations are done within transaction if processing guarantee
of the job is ProcessingGuarantee.EXACTLY_ONCE
.
All writes are done using default MongoDB codecs with POJO class codec added.
Example usage:
Sink<Document> mongoSink =
MongoSinks.builder(
"stream-sink",
Document.class,
dataLinkRef("someMongoDB")
)
.into("myDatabase", "myCollection")
.identifyDocumentBy("_id", doc -> doc.get("_id"))
.build()
);
Pipeline p = Pipeline.create();
(...)
someStage.writeTo(mongoSink);
Connector will use provided data link reference to obtain an instance of MongoClient
. Depending
on the configuration this client may be shared between processors or not.T
- type of the items the sink acceptsname
- name of the sinkdataLinkRef
- reference to mongo data linkitemClass
- type of document that will be saved@Beta public static Sink<org.bson.Document> mongodb(@Nonnull String name, @Nonnull String connectionString, @Nonnull String database, @Nonnull String collection)
builder(java.lang.String, java.lang.Class<T>, com.hazelcast.function.SupplierEx<com.mongodb.client.MongoClient>)
.
Example usage:
Sink<Document> mongoSink =
MongoSinks.builder(
"mongoSink",
"mongodb://127.0.0.1:27017",
"myDatabase",
"myCollection"
);
Pipeline p = Pipeline.create();
(...)
someStage.writeTo(mongoSink);
name
- name of this sinkconnectionString
- connection string to MongoDB instancedatabase
- database to which the documents will be put intocollection
- collection to which the documents will be put into@Beta public static Sink<org.bson.Document> mongodb(@Nonnull String name, @Nonnull DataLinkRef dataLinkRef, @Nonnull String database, @Nonnull String collection)
builder(java.lang.String, java.lang.Class<T>, com.hazelcast.function.SupplierEx<com.mongodb.client.MongoClient>)
.
Example usage:
Sink<Document> mongoSink =
MongoSinks.builder(
"mongoSink",
dataLinkRef("someMongoDB"),
"myDatabase",
"myCollection"
);
Pipeline p = Pipeline.create();
(...)
someStage.writeTo(mongoSink);
name
- name of this sinkdataLinkRef
- reference to some mongo data linkdatabase
- database to which the documents will be put intocollection
- collection to which the documents will be put intoCopyright © 2023 Hazelcast, Inc.. All rights reserved.