forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deletegroups.go
60 lines (49 loc) · 1.63 KB
/
deletegroups.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package kafka
import (
"context"
"fmt"
"net"
"time"
"github.com/streamdal/segmentio-kafka-go/protocol/deletegroups"
)
// DeleteGroupsRequest represents a request sent to a kafka broker to delete
// consumer groups.
type DeleteGroupsRequest struct {
// Address of the kafka broker to send the request to.
Addr net.Addr
// Identifiers of groups to delete.
GroupIDs []string
}
// DeleteGroupsResponse represents a response from a kafka broker to a consumer group
// deletion request.
type DeleteGroupsResponse struct {
// The amount of time that the broker throttled the request.
Throttle time.Duration
// Mapping of group ids to errors that occurred while attempting to delete those groups.
//
// The errors contain the kafka error code. Programs may use the standard
// errors.Is function to test the error against kafka error codes.
Errors map[string]error
}
// DeleteGroups sends a delete groups request and returns the response. The request is sent to the group coordinator of the first group
// of the request. All deleted groups must be managed by the same group coordinator.
func (c *Client) DeleteGroups(
ctx context.Context,
req *DeleteGroupsRequest,
) (*DeleteGroupsResponse, error) {
m, err := c.roundTrip(ctx, req.Addr, &deletegroups.Request{
GroupIDs: req.GroupIDs,
})
if err != nil {
return nil, fmt.Errorf("kafka.(*Client).DeleteGroups: %w", err)
}
r := m.(*deletegroups.Response)
ret := &DeleteGroupsResponse{
Throttle: makeDuration(r.ThrottleTimeMs),
Errors: make(map[string]error, len(r.Responses)),
}
for _, t := range r.Responses {
ret.Errors[t.GroupID] = makeError(t.ErrorCode, "")
}
return ret, nil
}