@@ -133,16 +133,15 @@ const (
133
133
ReadCommitted IsolationLevel = 1
134
134
)
135
135
136
- var (
137
- // DefaultClientID is the default value used as ClientID of kafka
138
- // connections.
139
- DefaultClientID string
140
- )
136
+ // DefaultClientID is the default value used as ClientID of kafka
137
+ // connections.
138
+ var DefaultClientID string
141
139
142
140
func init () {
143
141
progname := filepath .Base (os .Args [0 ])
144
142
hostname , _ := os .Hostname ()
145
143
DefaultClientID = fmt .Sprintf ("%s@%s (github.com/segmentio/kafka-go)" , progname , hostname )
144
+ DefaultTransport .(* Transport ).ClientID = DefaultClientID
146
145
}
147
146
148
147
// NewConn returns a new kafka connection for the given topic and partition.
@@ -263,10 +262,12 @@ func (c *Conn) Controller() (broker Broker, err error) {
263
262
}
264
263
for _ , brokerMeta := range res .Brokers {
265
264
if brokerMeta .NodeID == res .ControllerID {
266
- broker = Broker {ID : int (brokerMeta .NodeID ),
265
+ broker = Broker {
266
+ ID : int (brokerMeta .NodeID ),
267
267
Port : int (brokerMeta .Port ),
268
268
Host : brokerMeta .Host ,
269
- Rack : brokerMeta .Rack }
269
+ Rack : brokerMeta .Rack ,
270
+ }
270
271
break
271
272
}
272
273
}
@@ -322,7 +323,6 @@ func (c *Conn) findCoordinator(request findCoordinatorRequestV0) (findCoordinato
322
323
err := c .readOperation (
323
324
func (deadline time.Time , id int32 ) error {
324
325
return c .writeRequest (findCoordinator , v0 , id , request )
325
-
326
326
},
327
327
func (deadline time.Time , size int ) error {
328
328
return expectZeroSize (func () (remain int , err error ) {
@@ -340,32 +340,6 @@ func (c *Conn) findCoordinator(request findCoordinatorRequestV0) (findCoordinato
340
340
return response , nil
341
341
}
342
342
343
- // heartbeat sends a heartbeat message required by consumer groups
344
- //
345
- // See http://kafka.apache.org/protocol.html#The_Messages_Heartbeat
346
- func (c * Conn ) heartbeat (request heartbeatRequestV0 ) (heartbeatResponseV0 , error ) {
347
- var response heartbeatResponseV0
348
-
349
- err := c .writeOperation (
350
- func (deadline time.Time , id int32 ) error {
351
- return c .writeRequest (heartbeat , v0 , id , request )
352
- },
353
- func (deadline time.Time , size int ) error {
354
- return expectZeroSize (func () (remain int , err error ) {
355
- return (& response ).readFrom (& c .rbuf , size )
356
- }())
357
- },
358
- )
359
- if err != nil {
360
- return heartbeatResponseV0 {}, err
361
- }
362
- if response .ErrorCode != 0 {
363
- return heartbeatResponseV0 {}, Error (response .ErrorCode )
364
- }
365
-
366
- return response , nil
367
- }
368
-
369
343
// joinGroup attempts to join a consumer group
370
344
//
371
345
// See http://kafka.apache.org/protocol.html#The_Messages_JoinGroup
@@ -752,9 +726,8 @@ func (c *Conn) ReadBatch(minBytes, maxBytes int) *Batch {
752
726
// ReadBatchWith in every way is similar to ReadBatch. ReadBatch is configured
753
727
// with the default values in ReadBatchConfig except for minBytes and maxBytes.
754
728
func (c * Conn ) ReadBatchWith (cfg ReadBatchConfig ) * Batch {
755
-
756
729
var adjustedDeadline time.Time
757
- var maxFetch = int (c .fetchMaxBytes )
730
+ maxFetch : = int (c .fetchMaxBytes )
758
731
759
732
if cfg .MinBytes < 0 || cfg .MinBytes > maxFetch {
760
733
return & Batch {err : fmt .Errorf ("kafka.(*Conn).ReadBatch: minBytes of %d out of [1,%d] bounds" , cfg .MinBytes , maxFetch )}
@@ -960,7 +933,6 @@ func (c *Conn) readOffset(t int64) (offset int64, err error) {
960
933
// connection. If there are none, the method fetches all partitions of the kafka
961
934
// cluster.
962
935
func (c * Conn ) ReadPartitions (topics ... string ) (partitions []Partition , err error ) {
963
-
964
936
if len (topics ) == 0 {
965
937
if len (c .topic ) != 0 {
966
938
defaultTopics := [... ]string {c .topic }
@@ -1107,11 +1079,10 @@ func (c *Conn) writeCompressedMessages(codec CompressionCodec, msgs ...Message)
1107
1079
deadline = adjustDeadlineForRTT (deadline , now , defaultRTT )
1108
1080
switch produceVersion {
1109
1081
case v7 :
1110
- recordBatch , err :=
1111
- newRecordBatch (
1112
- codec ,
1113
- msgs ... ,
1114
- )
1082
+ recordBatch , err := newRecordBatch (
1083
+ codec ,
1084
+ msgs ... ,
1085
+ )
1115
1086
if err != nil {
1116
1087
return err
1117
1088
}
@@ -1126,11 +1097,10 @@ func (c *Conn) writeCompressedMessages(codec CompressionCodec, msgs ...Message)
1126
1097
recordBatch ,
1127
1098
)
1128
1099
case v3 :
1129
- recordBatch , err :=
1130
- newRecordBatch (
1131
- codec ,
1132
- msgs ... ,
1133
- )
1100
+ recordBatch , err := newRecordBatch (
1101
+ codec ,
1102
+ msgs ... ,
1103
+ )
1134
1104
if err != nil {
1135
1105
return err
1136
1106
}
@@ -1195,7 +1165,6 @@ func (c *Conn) writeCompressedMessages(codec CompressionCodec, msgs ...Message)
1195
1165
}
1196
1166
return size , err
1197
1167
}
1198
-
1199
1168
})
1200
1169
if err != nil {
1201
1170
return size , err
@@ -1555,7 +1524,7 @@ func (c *Conn) saslAuthenticate(data []byte) ([]byte, error) {
1555
1524
return nil , err
1556
1525
}
1557
1526
if version == v1 {
1558
- var request = saslAuthenticateRequestV0 {Data : data }
1527
+ request : = saslAuthenticateRequestV0 {Data : data }
1559
1528
var response saslAuthenticateResponseV0
1560
1529
1561
1530
err := c .writeOperation (
0 commit comments