UNPKG

couch-elastic-stream

Version:

data streaming from couchdb to elastic via kafka.

48 lines (40 loc) 1.17 kB
"use strict"; const { SourceConnector } = require("kafka-connect"); const NodeCouchDb = require('node-couchdb'); class CouchSourceConnector extends SourceConnector { start(properties, callback){ this.properties = properties; this.couch = new NodeCouchDb({ host : properties.host, port : properties.port, protocol : properties.protocol, auth: properties.auth }); this.couch.get('_all_dbs') .then((res) => { if(res.data.indexOf(properties.database) < 0) { callback(new Error(`${this.properties.database} DATABASE NOT FOUND`)); } return callback(null); }) .catch((error) => { callback(error); }); } taskConfigs(maxTasks, callback){ const taskConfig = { maxTasks, couch : this.couch, database: this.properties.database, partition: this.properties.partition, topic: this.properties.topic, maxPollCount: this.properties.maxPollCount, currentOffset: this.properties.currentOffset }; callback(null, taskConfig); } stop(){ console.log("STOP :: "); } } module.exports = CouchSourceConnector;