コード例 #1
0
ファイル: Ulisse.js プロジェクト: bitfinexcom/ulisse
  start () {
    this.reconnectDb()

    this.binlog = new ZongJi(this.conf.mysql)
    this.binlog.on('binlog', (evt) => {
      const query = this.parse(evt)
      if (!query) return

      if (query.type === 'row') {
        const table = this.table(query.table)
        table.handleRowChange(query)
      } else {
        if (_.indexOf(['BEGIN', 'COMMIT'], query.text) === -1) {
          this.emit('action', 'default', [{ a: 'dbe', o: query }])
        }
      }
    })

    function zerror (err) {
      this.emit('error-critical', err)
    }

    this.binlog.on('error', zerror.bind(this))
    this.binlog.ctrlConnection.on('error', zerror.bind(this))

    setInterval(() => {
      this.cli.ping(function (err) {
        if (err) console.error(err)
      })

      this.binlog.ctrlConnection.ping(function (err) {
        if (err) console.error(err)
      })
    }, this.conf.keepalive)

    this.binlog.start({
      startAtEnd: true,
      includeEvents: ['query', 'rotate', 'tablemap', 'writerows', 'updaterows', 'deleterows'],
      includeSchema: this.conf.schemas || undefined,
      serverId: this.conf.mysql.serverId || 0
    })
  }
コード例 #2
0
ファイル: index.js プロジェクト: jegutierrez/mysql-events
  socket.on('join', function(data){
    
    console.log('join -> '+ data.codcli + ':' + data.solucion)

    let zongji = new ZongJi({
      host     : conn.host,
      user     : conn.user,
      password : conn.password
    });

    let schema = {}
    schema[data.codcli] = [data.solucion]
    let events = ['tablemap','writerows', 'updaterows', 'deleterows']
  
    zongji.start({
      serverId: Math.floor(Math.random() * 999999) + 1,
      includeEvents: events,
      includeSchema: schema
    })

    zongji.on('binlog', function(evt) {
      console.log(evt)
      _changes(evt, function (err, before, after) {
        if (!err) {
          console.log(JSON.stringify(before)+' -> '+JSON.stringify(after))
          socket.emit( evt.tableMap[evt.tableId].tableName )
        }
      })
    })

    socket.on('disconnect', function () {
      console.log('Got SIGINT.');
      zongji.stop();
    })

    process.on('SIGINT', function() {
      console.log('Got SIGINT.');
      zongji.stop();
      process.exit();
    })
  })