You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"context""fmt""github.com/confluentinc/confluent-kafka-go/v2/kafka""github.com/gin-gonic/gin""github.com/spf13/viper""net/http""time"
)
varctx=context.Background()
// Config// Struct that holds local service port, remote redis host and porttypeConfigstruct {
Portint16KafkaAddressstringKafkaTopicstringKafkaConsumerGroupstring
}
typeIpMessagestruct {
Ipstring`json:"ip"`
}
funcloadConfig() Config {
viper.BindEnv("port")
viper.BindEnv("kafkaaddress")
viper.BindEnv("kafkatopic")
viper.BindEnv("kafkaconsumergroup")
config:=Config{}
config.Port=int16(viper.GetInt("port"))
config.KafkaAddress=viper.GetString("kafkaaddress")
config.KafkaTopic=viper.GetString("kafkatopic")
config.KafkaConsumerGroup=viper.GetString("kafkaconsumergroup")
returnconfig
}
funcStartKafkaReader(address, topic, groupstring) {
c, err:=kafka.NewConsumer(&kafka.ConfigMap{
"bootstrap.servers": address,
"group.id": group,
"auto.offset.reset": "earliest",
})
iferr!=nil {
panic(err)
}
c.SubscribeTopics([]string{topic}, nil)
// A signal handler or similar could be used to set this to false to break the loop.run:=trueforrun {
msg, err:=c.ReadMessage(time.Second)
iferr==nil {
fmt.Printf("Message on %s: %s\n", msg.TopicPartition, string(msg.Value))
} elseif!err.(kafka.Error).IsTimeout() {
// The client will automatically try to recover from all errors.// Timeout is not considered an error because it is raised by// ReadMessage in absence of messages.fmt.Printf("Consumer error: %v (%v)\n", err, msg)
}
}
c.Close()
}
funcmain() {
config:=loadConfig()
goStartKafkaReader(config.KafkaAddress, config.KafkaTopic, config.KafkaConsumerGroup)
router:=gin.Default()
router.GET("/health", func(ctx*gin.Context) { ctx.Status(http.StatusOK) })
fmt.Print("loaded")
router.Run("0.0.0.0:"+fmt.Sprint(config.Port))
}
Bug Description
When connecting to kafka in Go using confluent kafka we're seeing
Steps to Reproduce
Clone https://github.com/metalbear-co/playground
Change the following files to use confluent kafka:
ip-visit-consumer/main.go
add go go.mod
then run
go mod tidy
debug the app using GoLand
Backtrace
No response
Relevant Logs
No response
Your operating system and version
macOS m1
Local process
go binary
Local process version
No response
Additional Info
No response
The text was updated successfully, but these errors were encountered: