You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/12/26 15:19:32 UTC

[GitHub] [rocketmq-client-go] WJL3333 opened a new pull request #765: …

WJL3333 opened a new pull request #765:
URL: https://github.com/apache/rocketmq-client-go/pull/765


   ## What is the purpose of the change
   
   See #759
   
   ## Brief changelog
   
   1. change resetOffsetBody parse logic. support both gson and fastjson schema.
   ## Verifying this change
   start push consumer and trigger reset offset by mqadmin tool
   
   Follow this checklist to help us incorporate your contribution quickly and easily. Notice, `it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR`.
   
   - [x] Make sure there is a [Github issue](https://github.com/apache/rocketmq/issues) filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue. 
   - [x] Format the pull request title like `[ISSUE #123] Fix UnknownException when host config not exist`. Each commit in the pull request should have a meaningful subject line and body.
   - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [x] Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when a cross-module dependency exists.
   - [ ] If this contribution is large, please file an [Apache Individual Contributor License Agreement](http://www.apache.org/licenses/#clas).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq-client-go] WJL3333 commented on a change in pull request #765: [ISSUE #759] Change ResetOffsetBody response parse method to support fastjson schema

Posted by GitBox <gi...@apache.org>.
WJL3333 commented on a change in pull request #765:
URL: https://github.com/apache/rocketmq-client-go/pull/765#discussion_r775865349



##########
File path: internal/model.go
##########
@@ -295,12 +295,39 @@ type ResetOffsetBody struct {
 	OffsetTable map[primitive.MessageQueue]int64 `json:"offsetTable"`
 }
 
+// Decode note: the origin implementation for parse json is in gson format.
+// this func should support both gson and fastjson schema.
 func (resetOffsetBody *ResetOffsetBody) Decode(body []byte) {
+	validJSON := gjson.ValidBytes(body)
+
+	var offsetTable map[primitive.MessageQueue]int64
+
+	if validJSON {
+		offsetTable = parseGsonFormat(body)
+	} else {
+		offsetTable = parseFastJsonFormat(body)
+	}
+
+	resetOffsetBody.OffsetTable = offsetTable
+}
+
+func parseGsonFormat(body []byte) map[primitive.MessageQueue]int64 {
 	result := gjson.ParseBytes(body)
+
 	rlog.Debug("offset table string "+result.Get("offsetTable").String(), nil)
 
 	offsetTable := make(map[primitive.MessageQueue]int64, 0)
-	offsetTableArray := strings.Split(result.Get("offsetTable").String(), "],[")
+
+	offsetStr := result.Get("offsetTable").String()
+	if len(offsetStr) <= 2 {

Review comment:
       这里就只是简单防御性检查,一般情况下不会走这个逻辑




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq-client-go] maixiaohai commented on a change in pull request #765: [ISSUE #759] Change ResetOffsetBody response parse method to support fastjson schema

Posted by GitBox <gi...@apache.org>.
maixiaohai commented on a change in pull request #765:
URL: https://github.com/apache/rocketmq-client-go/pull/765#discussion_r775860371



##########
File path: internal/model.go
##########
@@ -295,12 +295,39 @@ type ResetOffsetBody struct {
 	OffsetTable map[primitive.MessageQueue]int64 `json:"offsetTable"`
 }
 
+// Decode note: the origin implementation for parse json is in gson format.
+// this func should support both gson and fastjson schema.
 func (resetOffsetBody *ResetOffsetBody) Decode(body []byte) {
+	validJSON := gjson.ValidBytes(body)
+
+	var offsetTable map[primitive.MessageQueue]int64
+
+	if validJSON {
+		offsetTable = parseGsonFormat(body)
+	} else {
+		offsetTable = parseFastJsonFormat(body)
+	}
+
+	resetOffsetBody.OffsetTable = offsetTable
+}
+
+func parseGsonFormat(body []byte) map[primitive.MessageQueue]int64 {
 	result := gjson.ParseBytes(body)
+
 	rlog.Debug("offset table string "+result.Get("offsetTable").String(), nil)
 
 	offsetTable := make(map[primitive.MessageQueue]int64, 0)
-	offsetTableArray := strings.Split(result.Get("offsetTable").String(), "],[")
+
+	offsetStr := result.Get("offsetTable").String()
+	if len(offsetStr) <= 2 {

Review comment:
       请教下,何时会触发这个情况




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq-client-go] WJL3333 commented on pull request #765: [ISSUE 759] Change ResetOffsetBody response parse method to support fastjson schema

Posted by GitBox <gi...@apache.org>.
WJL3333 commented on pull request #765:
URL: https://github.com/apache/rocketmq-client-go/pull/765#issuecomment-1001199843


   @maixiaohai @wenfengwang hello, i think the fix works as expect. PTAL.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [rocketmq-client-go] wenfengwang merged pull request #765: [ISSUE #759] Change ResetOffsetBody response parse method to support fastjson schema

Posted by GitBox <gi...@apache.org>.
wenfengwang merged pull request #765:
URL: https://github.com/apache/rocketmq-client-go/pull/765


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org