-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1010 from buyology/find-coordinator
refactor ConsumerMetadataReq/Resp -> FindCoordinatorReq/Resp
- Loading branch information
Showing
11 changed files
with
292 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package sarama | ||
|
||
type CoordinatorType int8 | ||
|
||
const ( | ||
CoordinatorGroup CoordinatorType = 0 | ||
CoordinatorTransaction CoordinatorType = 1 | ||
) | ||
|
||
type FindCoordinatorRequest struct { | ||
Version int16 | ||
CoordinatorKey string | ||
CoordinatorType CoordinatorType | ||
} | ||
|
||
func (f *FindCoordinatorRequest) encode(pe packetEncoder) error { | ||
if err := pe.putString(f.CoordinatorKey); err != nil { | ||
return err | ||
} | ||
|
||
if f.Version >= 1 { | ||
pe.putInt8(int8(f.CoordinatorType)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (f *FindCoordinatorRequest) decode(pd packetDecoder, version int16) (err error) { | ||
if f.CoordinatorKey, err = pd.getString(); err != nil { | ||
return err | ||
} | ||
|
||
if version >= 1 { | ||
f.Version = version | ||
coordinatorType, err := pd.getInt8() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
f.CoordinatorType = CoordinatorType(coordinatorType) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (f *FindCoordinatorRequest) key() int16 { | ||
return 10 | ||
} | ||
|
||
func (f *FindCoordinatorRequest) version() int16 { | ||
return f.Version | ||
} | ||
|
||
func (f *FindCoordinatorRequest) requiredVersion() KafkaVersion { | ||
switch f.Version { | ||
case 1: | ||
return V0_11_0_0 | ||
default: | ||
return V0_8_2_0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package sarama | ||
|
||
import "testing" | ||
|
||
var ( | ||
findCoordinatorRequestConsumerGroup = []byte{ | ||
0, 5, 'g', 'r', 'o', 'u', 'p', | ||
0, | ||
} | ||
|
||
findCoordinatorRequestTransaction = []byte{ | ||
0, 13, 't', 'r', 'a', 'n', 's', 'a', 'c', 't', 'i', 'o', 'n', 'i', 'd', | ||
1, | ||
} | ||
) | ||
|
||
func TestFindCoordinatorRequest(t *testing.T) { | ||
req := &FindCoordinatorRequest{ | ||
Version: 1, | ||
CoordinatorKey: "group", | ||
CoordinatorType: CoordinatorGroup, | ||
} | ||
|
||
testRequest(t, "version 1 - group", req, findCoordinatorRequestConsumerGroup) | ||
|
||
req = &FindCoordinatorRequest{ | ||
Version: 1, | ||
CoordinatorKey: "transactionid", | ||
CoordinatorType: CoordinatorTransaction, | ||
} | ||
|
||
testRequest(t, "version 1 - transaction", req, findCoordinatorRequestTransaction) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package sarama | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type FindCoordinatorResponse struct { | ||
Version int16 | ||
ThrottleTime time.Duration | ||
Err KError | ||
ErrMsg *string | ||
Coordinator *Broker | ||
} | ||
|
||
func (f *FindCoordinatorResponse) decode(pd packetDecoder, version int16) (err error) { | ||
if version >= 1 { | ||
f.Version = version | ||
|
||
throttleTime, err := pd.getInt32() | ||
if err != nil { | ||
return err | ||
} | ||
f.ThrottleTime = time.Duration(throttleTime) * time.Millisecond | ||
} | ||
|
||
tmp, err := pd.getInt16() | ||
if err != nil { | ||
return err | ||
} | ||
f.Err = KError(tmp) | ||
|
||
if version >= 1 { | ||
if f.ErrMsg, err = pd.getNullableString(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
coordinator := new(Broker) | ||
if err := coordinator.decode(pd); err != nil { | ||
return err | ||
} | ||
if coordinator.addr == ":0" { | ||
return nil | ||
} | ||
f.Coordinator = coordinator | ||
|
||
return nil | ||
} | ||
|
||
func (f *FindCoordinatorResponse) encode(pe packetEncoder) error { | ||
if f.Version >= 1 { | ||
pe.putInt32(int32(f.ThrottleTime / time.Millisecond)) | ||
} | ||
|
||
pe.putInt16(int16(f.Err)) | ||
|
||
if f.Version >= 1 { | ||
if err := pe.putNullableString(f.ErrMsg); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if err := f.Coordinator.encode(pe); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (f *FindCoordinatorResponse) key() int16 { | ||
return 10 | ||
} | ||
|
||
func (f *FindCoordinatorResponse) version() int16 { | ||
return f.Version | ||
} | ||
|
||
func (f *FindCoordinatorResponse) requiredVersion() KafkaVersion { | ||
switch f.Version { | ||
case 1: | ||
return V0_11_0_0 | ||
default: | ||
return V0_8_2_0 | ||
} | ||
} |
Oops, something went wrong.