MCPcopy
hub / github.com/IBM/sarama / main

Function main

examples/sasl_scram_client/main.go:64–173  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62}
63
64func main() {
65 flag.Parse()
66
67 if *brokers == "" {
68 log.Fatalln("at least one broker is required")
69 }
70 splitBrokers := strings.Split(*brokers, ",")
71
72 version, err := sarama.ParseKafkaVersion(*version)
73 if err != nil {
74 log.Panicf("Error parsing Kafka version: %v", err)
75 }
76
77 if *userName == "" {
78 log.Fatalln("SASL username is required")
79 }
80
81 if *passwd == "" {
82 log.Fatalln("SASL password is required")
83 }
84
85 conf := sarama.NewConfig()
86 conf.Producer.Retry.Max = 1
87 conf.Producer.RequiredAcks = sarama.WaitForAll
88 conf.Producer.Return.Successes = true
89 conf.Version = version
90 conf.ClientID = "sasl_scram_client"
91 conf.Metadata.Full = true
92 conf.Net.SASL.Enable = true
93 conf.Net.SASL.User = *userName
94 conf.Net.SASL.Password = *passwd
95 conf.Net.SASL.Handshake = true
96 if *algorithm == "sha512" {
97 conf.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &XDGSCRAMClient{HashGeneratorFcn: SHA512} }
98 conf.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA512
99 } else if *algorithm == "sha256" {
100 conf.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &XDGSCRAMClient{HashGeneratorFcn: SHA256} }
101 conf.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA256
102
103 } else {
104 log.Fatalf("invalid SHA algorithm \"%s\": can be either \"sha256\" or \"sha512\"", *algorithm)
105 }
106
107 if *useTLS {
108 conf.Net.TLS.Enable = true
109 conf.Net.TLS.Config = createTLSConfiguration()
110 }
111
112 if *mode == "consume" {
113 consumer, err := sarama.NewConsumer(splitBrokers, conf)
114 if err != nil {
115 panic(err)
116 }
117 log.Println("consumer created")
118 defer func() {
119 if err := consumer.Close(); err != nil {
120 log.Fatalln(err)
121 }

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
ConsumePartitionMethod · 0.95
SendMessageMethod · 0.95
CloseMethod · 0.95
ParseKafkaVersionFunction · 0.92
NewConfigFunction · 0.92
NewConsumerFunction · 0.92
NewSyncProducerFunction · 0.92
StringEncoderTypeAlias · 0.92
createTLSConfigurationFunction · 0.85
FatalfMethod · 0.80
PrintlnMethod · 0.65

Tested by

no test coverage detected