Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Don't connect to Kafka over SSL in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes committed Jun 10, 2024
1 parent 13c8a73 commit aaeb9a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ type KafkaConsumer struct {
statsChan chan PostHogEvent
}

func NewKafkaConsumer(brokers string, groupID string, topic string, geolocator *GeoLocator, outgoingChan chan PostHogEvent, statsChan chan PostHogEvent) (*KafkaConsumer, error) {
func NewKafkaConsumer(brokers string, securityProtocol string, groupID string, topic string, geolocator *GeoLocator, outgoingChan chan PostHogEvent, statsChan chan PostHogEvent) (*KafkaConsumer, error) {
config := &kafka.ConfigMap{
"bootstrap.servers": brokers,
"group.id": groupID,
"auto.offset.reset": "latest",
"enable.auto.commit": false,
"security.protocol": "SSL",
"security.protocol": securityProtocol,
}

consumer, err := kafka.NewConsumer(config)
Expand Down
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
func main() {
loadConfigs()

isProd := viper.GetBool("prod")

mmdb := viper.GetString("mmdb.path")
if mmdb == "" {
log.Fatal("mmdb.path must be set")
Expand Down Expand Up @@ -52,7 +54,11 @@ func main() {

go teamStats.keepStats(statsChan)

consumer, err := NewKafkaConsumer(brokers, groupID, topic, geolocator, phEventChan, statsChan)
kafkaSecurityProtocol := "SSL"
if !isProd {
kafkaSecurityProtocol = "PLAINTEXT"
}
consumer, err := NewKafkaConsumer(brokers, kafkaSecurityProtocol, groupID, topic, geolocator, phEventChan, statsChan)
if err != nil {
log.Fatalf("Failed to create Kafka consumer: %v", err)
}
Expand Down Expand Up @@ -258,7 +264,7 @@ func main() {
}
})

if !viper.GetBool("prod") {
if !isProd {
e.Logger.Fatal(e.Start(":8080"))
} else {
e.Logger.Fatal(e.StartAutoTLS(":443"))
Expand Down

0 comments on commit aaeb9a5

Please sign in to comment.