DescribeGroups calls the Kafka DescribeGroups API to get information about one or more consumer groups. See https://kafka.apache.org/protocol#The_Messages_DescribeGroups for more information.
( ctx context.Context, req *DescribeGroupsRequest, )
| 109 | // consumer groups. See https://kafka.apache.org/protocol#The_Messages_DescribeGroups for |
| 110 | // more information. |
| 111 | func (c *Client) DescribeGroups( |
| 112 | ctx context.Context, |
| 113 | req *DescribeGroupsRequest, |
| 114 | ) (*DescribeGroupsResponse, error) { |
| 115 | protoResp, err := c.roundTrip( |
| 116 | ctx, |
| 117 | req.Addr, |
| 118 | &describegroups.Request{ |
| 119 | Groups: req.GroupIDs, |
| 120 | }, |
| 121 | ) |
| 122 | if err != nil { |
| 123 | return nil, err |
| 124 | } |
| 125 | apiResp := protoResp.(*describegroups.Response) |
| 126 | resp := &DescribeGroupsResponse{} |
| 127 | |
| 128 | for _, apiGroup := range apiResp.Groups { |
| 129 | group := DescribeGroupsResponseGroup{ |
| 130 | Error: makeError(apiGroup.ErrorCode, ""), |
| 131 | GroupID: apiGroup.GroupID, |
| 132 | GroupState: apiGroup.GroupState, |
| 133 | } |
| 134 | |
| 135 | for _, member := range apiGroup.Members { |
| 136 | decodedMetadata, err := decodeMemberMetadata(member.MemberMetadata) |
| 137 | if err != nil { |
| 138 | group.Error = fmt.Errorf("failed to decode member metadata for group %s: %w", apiGroup.GroupID, err) |
| 139 | group.Members = nil // clear any previously decoded members |
| 140 | break |
| 141 | } |
| 142 | decodedAssignments, err := decodeMemberAssignments(member.MemberAssignment) |
| 143 | if err != nil { |
| 144 | group.Error = fmt.Errorf("failed to decode member assignments for group %s: %w", apiGroup.GroupID, err) |
| 145 | group.Members = nil // clear any previously decoded members |
| 146 | break |
| 147 | } |
| 148 | |
| 149 | group.Members = append(group.Members, DescribeGroupsResponseMember{ |
| 150 | MemberID: member.MemberID, |
| 151 | ClientID: member.ClientID, |
| 152 | ClientHost: member.ClientHost, |
| 153 | MemberAssignments: decodedAssignments, |
| 154 | MemberMetadata: decodedMetadata, |
| 155 | }) |
| 156 | } |
| 157 | resp.Groups = append(resp.Groups, group) |
| 158 | } |
| 159 | |
| 160 | return resp, nil |
| 161 | } |
| 162 | |
| 163 | // decodeMemberMetadata converts raw metadata bytes to a |
| 164 | // DescribeGroupsResponseMemberMetadata struct. |