@@ -222,7 +222,7 @@ process shutdown.
222
222
``` go
223
223
// make a new reader that consumes from topic-A, partition 0, at offset 42
224
224
r := kafka.NewReader (kafka.ReaderConfig {
225
- Brokers : []string {" localhost:9092" },
225
+ Brokers : []string {" localhost:9092" , " localhost:9093 " , " localhost:9094 " },
226
226
Topic : " topic-A" ,
227
227
Partition : 0 ,
228
228
MinBytes : 10e3 , // 10KB
@@ -253,7 +253,7 @@ ReadMessage automatically commits offsets when using consumer groups.
253
253
``` go
254
254
// make a new reader that consumes from topic-A
255
255
r := kafka.NewReader (kafka.ReaderConfig {
256
- Brokers : []string {" localhost:9092" },
256
+ Brokers : []string {" localhost:9092" , " localhost:9093 " , " localhost:9094 " },
257
257
GroupID : " consumer-group-id" ,
258
258
Topic : " topic-A" ,
259
259
MinBytes : 10e3 , // 10KB
@@ -317,7 +317,7 @@ by setting CommitInterval on the ReaderConfig.
317
317
``` go
318
318
// make a new reader that consumes from topic-A
319
319
r := kafka.NewReader (kafka.ReaderConfig {
320
- Brokers : []string {" localhost:9092" },
320
+ Brokers : []string {" localhost:9092" , " localhost:9093 " , " localhost:9094 " },
321
321
GroupID : " consumer-group-id" ,
322
322
Topic : " topic-A" ,
323
323
MinBytes : 10e3 , // 10KB
@@ -342,7 +342,7 @@ to use in most cases as it provides additional features:
342
342
``` go
343
343
// make a writer that produces to topic-A, using the least-bytes distribution
344
344
w := &kafka.Writer {
345
- Addr : kafka.TCP (" localhost:9092" ),
345
+ Addr : kafka.TCP (" localhost:9092" , " localhost:9093 " , " localhost:9094 " ),
346
346
Topic : " topic-A" ,
347
347
Balancer : &kafka.LeastBytes {},
348
348
}
@@ -376,7 +376,7 @@ if err := w.Close(); err != nil {
376
376
// Make a writer that publishes messages to topic-A.
377
377
// The topic will be created if it is missing.
378
378
w := &Writer{
379
- Addr : TCP (" localhost:9092" ),
379
+ Addr : kafka. TCP (" localhost:9092" , " localhost:9093 " , " localhost:9094 " ),
380
380
Topic : " topic-A" ,
381
381
AllowAutoTopicCreation : true ,
382
382
}
@@ -427,7 +427,7 @@ the topic on a per-message basis by setting `Message.Topic`.
427
427
428
428
``` go
429
429
w := &kafka.Writer {
430
- Addr : kafka.TCP (" localhost:9092" ),
430
+ Addr : kafka.TCP (" localhost:9092" , " localhost:9093 " , " localhost:9094 " ),
431
431
// NOTE: When Topic is not defined here, each Message must define it instead.
432
432
Balancer : &kafka.LeastBytes {},
433
433
}
@@ -478,7 +478,7 @@ aforementioned Sarama partitioners would route them to.
478
478
479
479
``` go
480
480
w := &kafka.Writer {
481
- Addr : kafka.TCP (" localhost:9092" ),
481
+ Addr : kafka.TCP (" localhost:9092" , " localhost:9093 " , " localhost:9094 " ),
482
482
Topic : " topic-A" ,
483
483
Balancer : &kafka.Hash {},
484
484
}
@@ -491,7 +491,7 @@ default ```consistent_random``` partition strategy.
491
491
492
492
``` go
493
493
w := &kafka.Writer {
494
- Addr : kafka.TCP (" localhost:9092" ),
494
+ Addr : kafka.TCP (" localhost:9092" , " localhost:9093 " , " localhost:9094 " ),
495
495
Topic : " topic-A" ,
496
496
Balancer : kafka.CRC32Balancer {},
497
497
}
@@ -505,7 +505,7 @@ the partition which is not permitted.
505
505
506
506
``` go
507
507
w := &kafka.Writer {
508
- Addr : kafka.TCP (" localhost:9092" ),
508
+ Addr : kafka.TCP (" localhost:9092" , " localhost:9093 " , " localhost:9094 " ),
509
509
Topic : " topic-A" ,
510
510
Balancer : kafka.Murmur2Balancer {},
511
511
}
@@ -517,7 +517,7 @@ Compression can be enabled on the `Writer` by setting the `Compression` field:
517
517
518
518
``` go
519
519
w := &kafka.Writer {
520
- Addr : kafka.TCP (" localhost:9092" ),
520
+ Addr : kafka.TCP (" localhost:9092" , " localhost:9093 " , " localhost:9094 " ),
521
521
Topic : " topic-A" ,
522
522
Compression : kafka.Snappy ,
523
523
}
@@ -559,7 +559,7 @@ dialer := &kafka.Dialer{
559
559
}
560
560
561
561
r := kafka.NewReader (kafka.ReaderConfig {
562
- Brokers : []string {" localhost:9093" },
562
+ Brokers : []string {" localhost:9092 " , " localhost: 9093" , " localhost:9094 " },
563
563
GroupID : " consumer-group-id" ,
564
564
Topic : " topic-A" ,
565
565
Dialer : dialer,
@@ -568,6 +568,20 @@ r := kafka.NewReader(kafka.ReaderConfig{
568
568
569
569
### Writer
570
570
571
+
572
+ Direct Writer creation
573
+
574
+ ``` go
575
+ w := kafka.Writer {
576
+ Addr : kafka.TCP (" localhost:9092" , " localhost:9093" , " localhost:9094" ),
577
+ Topic : " topic-A" ,
578
+ Balancer : &kafka.Hash {},
579
+ Transport : &kafka.Transport {
580
+ TLS: &tls.Config {},
581
+ },
582
+ }
583
+ ```
584
+
571
585
Using ` kafka.NewWriter `
572
586
573
587
``` go
@@ -578,26 +592,13 @@ dialer := &kafka.Dialer{
578
592
}
579
593
580
594
w := kafka.NewWriter (kafka.WriterConfig {
581
- Brokers : []string {" localhost:9093" },
595
+ Brokers : []string {" localhost:9092 " , " localhost: 9093" , " localhost:9094 " },
582
596
Topic : " topic-A" ,
583
597
Balancer : &kafka.Hash {},
584
598
Dialer : dialer,
585
599
})
586
600
```
587
-
588
- Direct Writer creation
589
-
590
- ``` go
591
- w := kafka.Writer {
592
- Addr : kafka.TCP (" localhost:9093" ),
593
- Topic : " topic-A" ,
594
- Balancer : &kafka.Hash {},
595
- Transport : &kafka.Transport {
596
- TLS: &tls.Config {},
597
- },
598
- }
599
-
600
- ```
601
+ Note that ` kafka.NewWriter ` and ` kafka.WriterConfig ` are deprecated and will be removed in a future release.
601
602
602
603
## SASL Support
603
604
@@ -654,7 +655,7 @@ dialer := &kafka.Dialer{
654
655
}
655
656
656
657
r := kafka.NewReader (kafka.ReaderConfig {
657
- Brokers : []string {" localhost:9093" },
658
+ Brokers : []string {" localhost:9092 " , " localhost: 9093" , " localhost:9094 " },
658
659
GroupID : " consumer-group-id" ,
659
660
Topic : " topic-A" ,
660
661
Dialer : dialer,
@@ -677,7 +678,7 @@ sharedTransport := &kafka.Transport{
677
678
}
678
679
679
680
w := kafka.Writer {
680
- Addr : kafka.TCP (" localhost:9092" ),
681
+ Addr : kafka.TCP (" localhost:9092" , " localhost:9093 " , " localhost:9094 " ),
681
682
Topic : " topic-A" ,
682
683
Balancer : &kafka.Hash {},
683
684
Transport : sharedTransport,
@@ -700,7 +701,7 @@ sharedTransport := &kafka.Transport{
700
701
}
701
702
702
703
client := &kafka.Client {
703
- Addr : kafka.TCP (" localhost:9092" ),
704
+ Addr : kafka.TCP (" localhost:9092" , " localhost:9093 " , " localhost:9094 " ),
704
705
Timeout : 10 * time.Second ,
705
706
Transport : sharedTransport,
706
707
}
@@ -714,7 +715,7 @@ endTime := time.Now()
714
715
batchSize := int (10e6 ) // 10MB
715
716
716
717
r := kafka.NewReader (kafka.ReaderConfig {
717
- Brokers : []string {" localhost:9092" },
718
+ Brokers : []string {" localhost:9092" , " localhost:9093 " , " localhost:9094 " },
718
719
Topic : " my-topic1" ,
719
720
Partition : 0 ,
720
721
MinBytes : batchSize,
@@ -756,7 +757,7 @@ func logf(msg string, a ...interface{}) {
756
757
}
757
758
758
759
r := kafka.NewReader (kafka.ReaderConfig {
759
- Brokers : []string {" localhost:9092" },
760
+ Brokers : []string {" localhost:9092" , " localhost:9093 " , " localhost:9094 " },
760
761
Topic : " my-topic1" ,
761
762
Partition : 0 ,
762
763
Logger : kafka.LoggerFunc (logf),
0 commit comments