Skip to content

standard JSON dont compat with go client #4471

@yuz10

Description

@yuz10

apache/rocketmq-client-go#845

BUG REPORT

in #4432 , the response of GET_ROUTEINFO_BY_TOPIC is changed, for example, the new format is:
{"brokerDatas":[{"brokerAddrs":{"0":"127.0.0.1:10911"}]}
the old is:
{"brokerDatas":[{"brokerAddrs":{0:"127.0.0.1:10911"}]}

the following go code in https://github.com/apache/rocketmq-client-go/blob/master/internal/route.go#L561

func (routeData *TopicRouteData) decode(data string) error {
	res := gjson.Parse(data)
	err := jsoniter.Unmarshal([]byte(res.Get("queueDatas").String()), &routeData.QueueDataList)

	if err != nil {
		return err
	}

	bds := res.Get("brokerDatas").Array()
	routeData.BrokerDataList = make([]*BrokerData, len(bds))
	for idx, v := range bds {
		bd := &BrokerData{
			BrokerName:      v.Get("brokerName").String(),
			Cluster:         v.Get("cluster").String(),
			BrokerAddresses: make(map[int64]string, 0),
		}
		addrs := v.Get("brokerAddrs").String()
		strs := strings.Split(addrs[1:len(addrs)-1], ",")
		if strs != nil {
			for _, str := range strs {
				i := strings.Index(str, ":")
				if i < 0 {
					continue
				}
				id, _ := strconv.ParseInt(str[0:i], 10, 64)
				bd.BrokerAddresses[id] = strings.Replace(str[i+1:], "\"", "", -1)
			}
		}
		routeData.BrokerDataList[idx] = bd
	}
	return nil
}

in id, _ := strconv.ParseInt(str[0:i], 10, 64) , if broker id is 1, then str[0:i] is "\"1\"", and strconv.ParseInt("\"1\"") will always be 0
so the producer will send message to slave.

I have submit a pull request in rocketmq-client-go, apache/rocketmq-client-go#846, but I think we should also be compatable with the old versions of go client.

  1. Please tell us about your environment:

  2. Other information (e.g. detailed explanation, logs, related issues, suggestions on how to fix, etc):

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions