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

feat: support tmq config msg.consume.rawdata #381

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions controller/ws/tmq/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const TaosTMQKey = "taos_tmq"
const (
TMQSubscribe = "subscribe"
TMQPoll = "poll"
TMQFetch = "fetch"
TMQFetch = "fetch" // fetch_raw_block
TMQFetchBlock = "fetch_block"
TMQFetchRaw = "fetch_raw"
TMQFetchRaw = "fetch_raw" // tmq_get_raw
TMQFetchJsonMeta = "fetch_json_meta"
TMQCommit = "commit"
TMQUnsubscribe = "unsubscribe"
Expand All @@ -16,7 +16,7 @@ const (
TMQCommitted = "committed"
TMQPosition = "position"
TMQListTopics = "list_topics"
TMQFetchRawNew = "fetch_raw_data"
TMQFetchRawData = "fetch_raw_data" // tmq_get_raw
)
const (
TMQRawMessage = 3
Expand Down
19 changes: 16 additions & 3 deletions controller/ws/tmq/tmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func NewTMQController() *TMQController {
return
}
t.fetchRawBlock(ctx, session, &req)
case TMQFetchRawNew:
case TMQFetchRawData:
var req TMQFetchRawReq
err = json.Unmarshal(action.Args, &req)
if err != nil {
Expand Down Expand Up @@ -400,6 +400,7 @@ type TMQSubscribeReq struct {
TZ string `json:"tz"`
App string `json:"app"`
IP string `json:"ip"`
MsgConsumeRawdata string `json:"msg_consume_rawdata"`
}

type TMQSubscribeResp struct {
Expand Down Expand Up @@ -520,6 +521,9 @@ func (t *TMQ) subscribe(ctx context.Context, session *melody.Session, req *TMQSu
if len(req.MaxPollIntervalMS) != 0 {
tmqOptions["max.poll.interval.ms"] = req.MaxPollIntervalMS
}
if len(req.MsgConsumeRawdata) != 0 {
tmqOptions["msg.consume.rawdata"] = req.MsgConsumeRawdata
}
var errCode int32
for k, v := range tmqOptions {
errCode = wrapper.TMQConfSet(tmqConfig, k, v)
Expand Down Expand Up @@ -1009,7 +1013,7 @@ func (t *TMQ) fetchRawBlock(ctx context.Context, session *melody.Session, req *T
}

func (t *TMQ) fetchRawBlockNew(ctx context.Context, session *melody.Session, req *TMQFetchRawReq) {
action := TMQFetchRawNew
action := TMQFetchRawData
logger := t.logger.WithField("action", action).WithField(config.ReqIDKey, req.ReqID)
logger.Tracef("fetch raw request:%+v", req)
if t.consumer == nil {
Expand Down Expand Up @@ -1090,6 +1094,11 @@ func (t *TMQ) fetchJsonMeta(ctx context.Context, session *melody.Session, req *T
return
}
message := t.tmpMessage
if !canGetMeta(message.Type) {
logger.Errorf("message type can not get meta, type:%d", message.Type)
wsTMQErrorMsg(ctx, session, logger, 0xffff, fmt.Sprintf("message type can not get meta, type: %d", message.Type), action, req.ReqID, &req.MessageID)
return
}
if message.Index != req.MessageID {
logger.Errorf("message ID are not equal, req:%d, message:%d", req.MessageID, message.Index)
wsTMQErrorMsg(ctx, session, logger, 0xffff, "message ID is not equal", action, req.ReqID, &req.MessageID)
Expand Down Expand Up @@ -1368,9 +1377,13 @@ func canGetData(messageType int32) bool {
return messageType == common.TMQ_RES_DATA || messageType == common.TMQ_RES_METADATA
}

func canGetMeta(messageType int32) bool {
return messageType == common.TMQ_RES_TABLE_META || messageType == common.TMQ_RES_METADATA
}

func messageTypeIsValid(messageType int32) bool {
switch messageType {
case common.TMQ_RES_DATA, common.TMQ_RES_TABLE_META, common.TMQ_RES_METADATA:
case common.TMQ_RES_DATA, common.TMQ_RES_TABLE_META, common.TMQ_RES_METADATA, common.TMQ_RES_RAWDATA:
return true
}
return false
Expand Down
Loading
Loading