withlin / canal-go

Alibaba mysql database binlog incremental subscription & consumer components Canal's golang client[阿里巴巴mysql数据库binlog的增量订阅&消费组件 Canal 的 go 客户端 ] https://github.com/alibaba/canal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

整理文档

withlin opened this issue · comments

commented

as title

将message.entries打印出来是这样的模样,这是什么问题呢,不能可视化的看到操作语句
[]com_alibaba_otter_canal_protocol.Entry{com_alibaba_otter_canal_protocol.Entry{Header:(*com_alibaba_otter_canal_protocol.Header)(0xc00010a000), EntryTypePresent:(*com_alibaba_otter_canal_protocol.Entry_EntryType)(0xc0000f8044), StoreValue:[]uint8{0x20, 0xb}, XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}, com_alibaba_otter_canal_protocol.Entry{Header:(*com_alibaba_otter_canal_protocol.Header)(0xc00010a0e0), EntryTypePresent:(*com_alibaba_otter_canal_protocol.Entry_EntryType)(0xc0000f8070), StoreValue:[]uint8{0x12, 0x4, 0x31, 0x38, 0x38, 0x30}, XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}}

commented

麻烦看一下 samples
里面有说,因为entries 还需要进一步解析

func printEntry(entrys []protocol.Entry) {

	for _, entry := range entrys {
		if entry.GetEntryType() == protocol.EntryType_TRANSACTIONBEGIN || entry.GetEntryType() == protocol.EntryType_TRANSACTIONEND {
			continue
		}
		rowChange := new(protocol.RowChange)

		err := proto.Unmarshal(entry.GetStoreValue(), rowChange)
		checkError(err)
		if rowChange != nil {
			eventType := rowChange.GetEventType()
			header := entry.GetHeader()
			fmt.Println(fmt.Sprintf("================> binlog[%s : %d],name[%s,%s], eventType: %s", header.GetLogfileName(), header.GetLogfileOffset(), header.GetSchemaName(), header.GetTableName(), header.GetEventType()))

			for _, rowData := range rowChange.GetRowDatas() {
				if eventType == protocol.EventType_DELETE {
					printColumn(rowData.GetBeforeColumns())
				} else if eventType == protocol.EventType_INSERT {
					printColumn(rowData.GetAfterColumns())
				} else {
					fmt.Println("-------> before")
					printColumn(rowData.GetBeforeColumns())
					fmt.Println("-------> after")
					printColumn(rowData.GetAfterColumns())
				}
			}
		}
	}
}

func printColumn(columns []*protocol.Column) {
	for _, col := range columns {
		fmt.Println(fmt.Sprintf("%s : %s  update= %t", col.GetName(), col.GetValue(), col.GetUpdated()))
	}
}

image
每次都是只有解析到begin/end