聊聊canal-go的position

本文主要研究一下canal-go的position

Position

canal-go-v1.0.7/protocol/Position/Position.go

package position

type Position interface {
}
  • Position.go定义了一个Position接口

MetaqPosition

canal-go-v1.0.7/protocol/Position/metaq_position.go

package position

type MetaqPosition struct {
    Topic    string
    MsgNewId string
    Offset   int64
}
  • MetaqPosition定义了Topic、MsgNewId、Offset属性

TimePosition

canal-go-v1.0.7/protocol/Position/time_position.go

package position

type TimePosition struct {
    Timestamp int64
}

func NewTimePosition(timestamp int64) *TimePosition {
    tstamp := &TimePosition{Timestamp: timestamp}
    return tstamp
}
  • TimePosition定义了Timestamp属性,NewTimePosition方法实例化TimePosition

EntryPosition

canal-go-v1.0.7/protocol/Position/entry_position.go

package position

const (
    EVENTIDENTITY_SEGMENT = 3
    EVENTIDENTITY_SPLIT   = 5
)

type EntryPosition struct {
    TimePosition
    Included    bool
    JournalName string
    Position    int64
    ServerId    int64
}

func NewEntryPosition(journalName string, position int64, timestamp int64, serverId int64, Included bool) *EntryPosition {
    entryPosition := &EntryPosition{TimePosition{timestamp}, false, journalName, position, serverId}
    return entryPosition
}
  • EntryPosition定义了TimePosition、Included、JournalName、Position、ServerId属性;NewEntryPosition方法实例一个EntryPosition

LogPosition

go-projects/canal-go-v1.0.7/protocol/Position/log_position.go

package position

type LogPosition struct {
    Identity LogIdentity
    Postion  EntryPosition
}
  • LogPosition定义了LogIdentity、EntryPosition属性

小结

canal-go定义了Position、MetaqPosition、TimePosition、EntryPosition、LogPosition

doc

你可能感兴趣的:(canal)