kafkaclient

package
v0.0.58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2024 License: MIT, MIT Imports: 7 Imported by: 0

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

Functions

func DefaultProducerConfiguration

func DefaultProducerConfiguration(clientID string, username string, password string) *sarama.Config

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

func NonSSLProducerConfiguration(clientID string) *sarama.Config

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL