Documentation ¶
Overview ¶
package kafkaclient exists to ease the use of the Sarama library for Go-based Kafka producers. It provides a simple way to create a producer configuration that can be used to connect to a Kafka cluster using SASL and TLS. All configuration is able to be changed by the consuming application.
Example ¶
package main import ( "fmt" "github.com/cultureamp/ca-go/x/sarama/kafkaclient" ) func main() { // the default behaviour can be overridden in local environments localEnv := false config := kafkaclient.DefaultProducerConfiguration("application_name", "username", "passwordvaluefromsecret") if localEnv { config.Net.TLS.Enable = false config.Net.SASL.Enable = false } fmt.Printf("ClientID=%s TLS:enabled=%t SASL:enabled=%t\n", config.ClientID, config.Net.TLS.Enable, config.Net.SASL.Enable) }
Output: ClientID=application_name TLS:enabled=true SASL:enabled=true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( SHA256 scram.HashGeneratorFcn = sha256.New SHA512 scram.HashGeneratorFcn = sha512.New )
Functions ¶
func DefaultProducerConfiguration ¶
DefaultProducerConfiguration creates a Sarama configuration with the default settings appropriate for use by a Sarama SyncProducer in a SASL environment.
Example (Production) ¶
package main import ( "fmt" "github.com/cultureamp/ca-go/x/sarama/kafkaclient" ) func main() { config := kafkaclient.DefaultProducerConfiguration("application_name", "username", "passwordvaluefromsecret") fmt.Printf("ClientID=%s TLS:enabled=%t SASL:enabled=%t\n", config.ClientID, config.Net.TLS.Enable, config.Net.SASL.Enable) }
Output: ClientID=application_name TLS:enabled=true SASL:enabled=true
Example (Testingoverrides) ¶
package main import ( "fmt" "github.com/cultureamp/ca-go/x/sarama/kafkaclient" ) func main() { config := kafkaclient.DefaultProducerConfiguration("application_name", "username", "passwordvaluefromsecret") // for testing, disable TLS and SASL when connecting to a local Kafka instance config.Net.TLS.Enable = false config.Net.SASL.Enable = false fmt.Printf("ClientID=%s TLS:enabled=%t SASL:enabled=%t\n", config.ClientID, config.Net.TLS.Enable, config.Net.SASL.Enable) }
Output: ClientID=application_name TLS:enabled=false SASL:enabled=false
func EnableDebugLog ¶
func EnableDebugLog()
EnableDebugLog provides more details on how sarama connecting to brokers.
func NonSSLProducerConfiguration ¶
NonSSLProducerConfiguration creates a Sarama configuration with the default settings without SSL config appropriate for use to test connection with local Kafka.
Types ¶
This section is empty.