handler.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package canal
  2. import (
  3. "github.com/go-mysql-org/go-mysql/mysql"
  4. "github.com/go-mysql-org/go-mysql/replication"
  5. )
  6. type EventHandler interface {
  7. OnRotate(roateEvent *replication.RotateEvent) error
  8. // OnTableChanged is called when the table is created, altered, renamed or dropped.
  9. // You need to clear the associated data like cache with the table.
  10. // It will be called before OnDDL.
  11. OnTableChanged(schema string, table string) error
  12. OnDDL(nextPos mysql.Position, queryEvent *replication.QueryEvent) error
  13. OnRow(e *RowsEvent) error
  14. OnXID(nextPos mysql.Position) error
  15. OnGTID(gtid mysql.GTIDSet) error
  16. // OnPosSynced Use your own way to sync position. When force is true, sync position immediately.
  17. OnPosSynced(pos mysql.Position, set mysql.GTIDSet, force bool) error
  18. String() string
  19. }
  20. type DummyEventHandler struct {
  21. }
  22. func (h *DummyEventHandler) OnRotate(*replication.RotateEvent) error { return nil }
  23. func (h *DummyEventHandler) OnTableChanged(schema string, table string) error { return nil }
  24. func (h *DummyEventHandler) OnDDL(nextPos mysql.Position, queryEvent *replication.QueryEvent) error {
  25. return nil
  26. }
  27. func (h *DummyEventHandler) OnRow(*RowsEvent) error { return nil }
  28. func (h *DummyEventHandler) OnXID(mysql.Position) error { return nil }
  29. func (h *DummyEventHandler) OnGTID(mysql.GTIDSet) error { return nil }
  30. func (h *DummyEventHandler) OnPosSynced(mysql.Position, mysql.GTIDSet, bool) error { return nil }
  31. func (h *DummyEventHandler) String() string { return "DummyEventHandler" }
  32. // `SetEventHandler` registers the sync handler, you must register your
  33. // own handler before starting Canal.
  34. func (c *Canal) SetEventHandler(h EventHandler) {
  35. c.eventHandler = h
  36. }