-
Notifications
You must be signed in to change notification settings - Fork 1
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 #2 from Roshick/beta
Migrate from franz-go to sarama
- Loading branch information
Showing
7 changed files
with
273 additions
and
205 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,20 @@ | ||
package aukafka | ||
|
||
import ( | ||
"crypto/tls" | ||
"net" | ||
"time" | ||
import "github.com/IBM/sarama" | ||
|
||
"github.com/twmb/franz-go/pkg/kgo" | ||
"github.com/twmb/franz-go/pkg/sasl" | ||
"github.com/twmb/franz-go/pkg/sasl/plain" | ||
"github.com/twmb/franz-go/pkg/sasl/scram" | ||
) | ||
|
||
func defaultTopicOptions(logKey string, config TopicConfig) []kgo.Opt { | ||
tlsDialer := &tls.Dialer{ | ||
NetDialer: &net.Dialer{Timeout: 10 * time.Second}, | ||
Config: &tls.Config{InsecureSkipVerify: true}, | ||
} | ||
|
||
var mechanism sasl.Mechanism | ||
switch config.AuthType { | ||
case "sha256": | ||
mechanism = scram.Auth{ | ||
User: config.Username, | ||
Pass: config.Password, | ||
}.AsSha256Mechanism() | ||
case "plain": | ||
fallthrough | ||
default: | ||
mechanism = plain.Auth{ | ||
User: config.Username, | ||
Pass: config.Password, | ||
}.AsMechanism() | ||
func mergeConfigWithPreset( | ||
topicConfig TopicConfig, | ||
configPreset *sarama.Config, | ||
) (*sarama.Config, error) { | ||
var clientConfig *sarama.Config | ||
if configPreset != nil { | ||
clientConfig = configPreset | ||
} else { | ||
clientConfig = sarama.NewConfig() | ||
} | ||
|
||
opts := []kgo.Opt{ | ||
kgo.SeedBrokers(config.Brokers...), | ||
kgo.SASL(mechanism), | ||
kgo.Dialer(tlsDialer.DialContext), | ||
kgo.SessionTimeout(30 * time.Second), | ||
kgo.RequestRetries(2), | ||
kgo.RetryTimeout(5 * time.Second), | ||
kgo.WithLogger(Logger{Key: logKey}), | ||
} | ||
|
||
return opts | ||
clientConfig.Net.SASL.User = topicConfig.Username | ||
clientConfig.Net.SASL.Password = topicConfig.Password | ||
clientConfig.Net.SASL.Enable = true | ||
clientConfig.Net.SASL.Mechanism = sarama.SASLMechanism(topicConfig.AuthType) | ||
return clientConfig, nil | ||
} |
Oops, something went wrong.