use of org.apache.connect.mongo.SourceTaskConfig in project rocketmq-externals by apache.
the class MongoSourceTask method start.
@Override
public void start(KeyValue config) {
try {
sourceTaskConfig = new SourceTaskConfig();
sourceTaskConfig.load(config);
replicaSetsContext = new ReplicaSetsContext(sourceTaskConfig);
replicaSetManager = ReplicaSetManager.create(sourceTaskConfig.getMongoAddr());
replicaSetManager.getReplicaConfigByName().forEach((replicaSetName, replicaSetConfig) -> {
ByteBuffer byteBuffer = this.context.positionStorageReader().getPosition(ByteBuffer.wrap(replicaSetName.getBytes()));
if (byteBuffer != null && byteBuffer.array().length > 0) {
String positionJson = new String(byteBuffer.array(), StandardCharsets.UTF_8);
Position position = JSONObject.parseObject(positionJson, Position.class);
replicaSetConfig.setPosition(position);
} else {
Position position = new Position();
position.setTimeStamp(sourceTaskConfig.getPositionTimeStamp());
position.setInc(sourceTaskConfig.getPositionInc());
position.setInitSync(sourceTaskConfig.isDataSync());
replicaSetConfig.setPosition(position);
}
ReplicaSet replicaSet = new ReplicaSet(replicaSetConfig, replicaSetsContext);
replicaSetsContext.addReplicaSet(replicaSet);
replicaSet.start();
});
} catch (Throwable throwable) {
logger.error("task start error", throwable);
stop();
}
}
Aggregations