Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改kafka输出格式,适配starrocks #174

Open
wants to merge 1 commit into
base: v1.8.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion plugin/kafka/src/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ func (This *Conn) getMsg(data *pluginDriver.PluginDataType) (*sarama.ProducerMes
Key := fmt.Sprint(pluginDriver.TransfeResult(This.p.Key,data,len(data.Rows)-1))
msg.Key = sarama.StringEncoder(Key)
}

// 适配StarRocks里的kafka格式,将更新前的数据被去掉了,只留下更新后的数据。
if len(data.Rows) == 2 && data.EventType == "update" {
data.Rows = data.Rows[1:]
}

c,err := json.Marshal(data)
if err != nil{
Expand All @@ -226,6 +231,12 @@ func (This *Conn) sendToList(data *pluginDriver.PluginDataType,retry bool,isComm
LastSuccessCommitData,err = This.sendToKafkaByBatch()
goto endErr
}

// 如果是sql或者commit类型,则不加入dataList发送到kafka中,兼容StarRocks,对端无法识别这类数据
if data.EventType == "sql" || data.EventType == "commit" {
goto endErr
}

if This.p.BatchSize > 1 {
if retry == false {
var msg *sarama.ProducerMessage
Expand Down Expand Up @@ -333,4 +344,4 @@ func (This *Conn) sendToKafkaByBatch() (*pluginDriver.PluginDataType, error) {

func (This *Conn) TimeOutCommit() (*pluginDriver.PluginDataType, *pluginDriver.PluginDataType,error) {
return This.sendToList(nil,true,false)
}
}