electleaders.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package electleaders
  2. import "github.com/segmentio/kafka-go/protocol"
  3. func init() {
  4. protocol.Register(&Request{}, &Response{})
  5. }
  6. // Detailed API definition: https://kafka.apache.org/protocol#The_Messages_ElectLeaders
  7. type Request struct {
  8. ElectionType int8 `kafka:"min=v1,max=v1"`
  9. TopicPartitions []RequestTopicPartitions `kafka:"min=v0,max=v1"`
  10. TimeoutMs int32 `kafka:"min=v0,max=v1"`
  11. }
  12. type RequestTopicPartitions struct {
  13. Topic string `kafka:"min=v0,max=v1"`
  14. PartitionIDs []int32 `kafka:"min=v0,max=v1"`
  15. }
  16. func (r *Request) ApiKey() protocol.ApiKey { return protocol.ElectLeaders }
  17. func (r *Request) Broker(cluster protocol.Cluster) (protocol.Broker, error) {
  18. return cluster.Brokers[cluster.Controller], nil
  19. }
  20. type Response struct {
  21. ThrottleTime int32 `kafka:"min=v0,max=v1"`
  22. ErrorCode int16 `kafka:"min=v1,max=v1"`
  23. ReplicaElectionResults []ResponseReplicaElectionResult `kafka:"min=v0,max=v1"`
  24. }
  25. type ResponseReplicaElectionResult struct {
  26. Topic string `kafka:"min=v0,max=v1"`
  27. PartitionResults []ResponsePartitionResult `kafka:"min=v0,max=v1"`
  28. }
  29. type ResponsePartitionResult struct {
  30. PartitionID int32 `kafka:"min=v0,max=v1"`
  31. ErrorCode int16 `kafka:"min=v0,max=v1"`
  32. ErrorMessage string `kafka:"min=v0,max=v1,nullable"`
  33. }
  34. func (r *Response) ApiKey() protocol.ApiKey { return protocol.ElectLeaders }