@@ -30,8 +30,8 @@ type IngestRule struct {
3030 Index string `toml:"index"`
3131 ColumnMap map [string ][]string `toml:"column_map"`
3232 JsonColumnName string `toml:"json_column_name"`
33- JsonTypeName string `toml:"json_type_name"` // optional used for tao_objects type column ex: user or post or comment
34- JsonTypeValue int `toml:"json_type_value"` // optional used for tao_objects type column ex: 1 or 3 or 4
33+ JsonTypeName string `toml:"json_type_name"` // optional used for tao_objects type column name ex: type
34+ JsonTypeValue int `toml:"json_type_value"` // optional used for tao_objects type column value ex: 1 or 3 or 4
3535 timeProvider func () time.Time
3636
3737 // MySQL table information
@@ -158,6 +158,7 @@ func (r *IngestRule) Apply(e *canal.RowsEvent) ([]TableRowChange, error) {
158158 if err != nil {
159159 return nil , errors .Trace (err )
160160 }
161+
161162 switch e .Action {
162163 case canal .InsertAction :
163164 return r .makeInsertChangeSet (e , idColNo )
@@ -172,7 +173,9 @@ func (r *IngestRule) Apply(e *canal.RowsEvent) ([]TableRowChange, error) {
172173// ApplyRuleSet converts row event to document changeset and sends to the channel c
173174func ApplyRuleSet (ruleSet []IngestRule , e * canal.RowsEvent , c chan interface {}) (uint64 , error ) {
174175 var docCount uint64
175- var ts = time .Now ().UTC ()
176+
177+ // Publish Minimal Row Event - without payload
178+ processRowEventForNats (e )
176179
177180 for ruleID := range ruleSet {
178181 rule := ruleSet [ruleID ]
@@ -181,37 +184,22 @@ func ApplyRuleSet(ruleSet []IngestRule, e *canal.RowsEvent, c chan interface{})
181184 return docCount , errors .Trace (err )
182185 }
183186
184- // Log skipped event
185- if docs == nil && rule .JsonTypeValue > 0 {
186- log .Infof (
187- "[row event skipped] ruleId=%d index=%s table=%s type!=%d action=%s rows=%d timeStamp=%s" ,
188- ruleID ,
189- rule .Index ,
190- e .Table ,
191- rule .JsonTypeValue ,
192- e .Action ,
193- rowCount (e ),
194- ts .String (),
195- )
196- }
197-
198187 if docs != nil {
199188 log .Infof (
200- "[row event] ruleId=%d index=%s table=%s type=%d action=%s rows=%d docs=%v timeStamp=%s " ,
189+ "[rule event] ruleId=%d index=%s table=%s type=%d action=%s rows=%d docs=%v" ,
201190 ruleID ,
202191 rule .Index ,
203192 e .Table ,
204193 rule .JsonTypeValue ,
205194 e .Action ,
206195 rowCount (e ),
207196 DocIDList (docs ),
208- ts .String (),
209197 )
198+
210199 for _ , doc := range docs {
211200 c <- doc
212201 docCount ++
213-
214- PublishRowToNats (doc , rule )
202+ // PublishDocToNats(doc, rule)
215203 }
216204 }
217205 }
@@ -427,3 +415,49 @@ func isJsonRowTypeValid(e *canal.RowsEvent, typColNo, typColVal int) (bool, erro
427415
428416 return false , nil
429417}
418+
419+ func processRowEventForNats (e * canal.RowsEvent ) {
420+ idColNo , _ := fieldIndex (e , "id" )
421+ typColNo , _ := fieldIndex (e , "type" )
422+
423+ if e .Action == "update" {
424+ for i := 0 ; i < len (e .Rows )/ 2 ; i ++ {
425+ var id uint64
426+ var typ uint32
427+ newRow := e .Rows [i * 2 + 1 ]
428+
429+ if idColNo >= 0 {
430+ id , _ = util .CoerceToUint64 (newRow [idColNo ])
431+ }
432+
433+ if typColNo >= 0 {
434+ typ , _ = util .CoerceToUint32 (newRow [typColNo ])
435+ }
436+
437+ if id > 0 && typ > 0 {
438+ PublishRowToNats (id , typ , e .Action , e .Table .String ())
439+ log .Debugf ("[row event] table=%s type=%d action=%s id=%d" , e .Table , typ , e .Action , id )
440+ }
441+ }
442+ }
443+
444+ if e .Action == "insert" || e .Action == "delete" {
445+ for _ , row := range e .Rows {
446+ var id uint64
447+ var typ uint32
448+
449+ if idColNo >= 0 {
450+ id , _ = util .CoerceToUint64 (row [idColNo ])
451+ }
452+
453+ if typColNo >= 0 {
454+ typ , _ = util .CoerceToUint32 (row [typColNo ])
455+ }
456+
457+ if id > 0 && typ > 0 {
458+ PublishRowToNats (id , typ , e .Action , e .Table .String ())
459+ log .Debugf ("[row event] table=%s type=%d action=%s id=%d" , e .Table , typ , e .Action , id )
460+ }
461+ }
462+ }
463+ }
0 commit comments