Skip to content

Commit 44a678e

Browse files
docs(readme): add example of using SASL with Client (#809)
1 parent 8dfb915 commit 44a678e

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

README.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ software.
3232

3333
#### Note:
3434

35-
In order to better align with our newly adopted Code of Conduct, the kafka-go project has renamed our default branch to `main`.
35+
In order to better align with our newly adopted Code of Conduct, the kafka-go project has renamed our default branch to `main`.
3636
For the full details of our Code Of Conduct see [this](./CODE_OF_CONDUCT.md) document.
3737

3838
## Migrating to 0.4
@@ -625,18 +625,41 @@ if err != nil {
625625
panic(err)
626626
}
627627

628-
dialer := &kafka.Dialer{
629-
Timeout: 10 * time.Second,
630-
DualStack: true,
628+
// Transports are responsible for managing connection pools and other resources,
629+
// it's generally best to create a few of these and share them across your
630+
// application.
631+
sharedTransport := &kafka.Transport{
631632
SASLMechanism: mechanism,
632633
}
633634

634-
w := kafka.NewWriter(kafka.WriterConfig{
635-
Brokers: []string{"localhost:9093"},
636-
Topic: "topic-A",
637-
Balancer: &kafka.Hash{},
638-
Dialer: dialer,
639-
})
635+
w := kafka.Writer{
636+
Addr: kafka.TCP("localhost:9092"),
637+
Topic: "topic-A",
638+
Balancer: &kafka.Hash{},
639+
Transport: sharedTransport,
640+
}
641+
```
642+
643+
### Client
644+
645+
```go
646+
mechanism, err := scram.Mechanism(scram.SHA512, "username", "password")
647+
if err != nil {
648+
panic(err)
649+
}
650+
651+
// Transports are responsible for managing connection pools and other resources,
652+
// it's generally best to create a few of these and share them across your
653+
// application.
654+
sharedTransport := &kafka.Transport{
655+
SASLMechanism: mechanism,
656+
}
657+
658+
client := &kafka.Client{
659+
Addr: kafka.TCP("localhost:9092"),
660+
Timeout: 10 * time.Second,
661+
Transport: sharedTransport,
662+
}
640663
```
641664

642665
#### Reading all messages within a time range

0 commit comments

Comments
 (0)