goapache-kafkaconfluent-cloud

go client example of a kafka consumer for confluent cloud with sasl.username and sasl.password


Does anyone have a go client example of a Kafka consumer for the confluent cloud with sasl.username and sasl.password?

I am running into an error while trying to consume a message from the confluent cloud.

Failed to connect to Kafka broker: kafka: client has run out of available brokers to talk to: EOF

Solution

  • Confluent has their own repo for examples

    https://github.com/confluentinc/confluent-kafka-go/blob/master/examples/confluent_cloud_example/confluent_cloud_example.go

    Extract

        bootstrapServers          = "<BOOTSTRAP_SERVERS>"
        ccloudAPIKey              = "<CCLOUD_API_KEY>"
        ccloudAPISecret           = "<CCLOUD_API_SECRET>"
        schemaRegistryAPIEndpoint = "<CCLOUD_SR_ENDPOINT>"
        schemaRegistryAPIKey      = "<CCLOUD_SR_API_KEY>"
        schemaRegistryAPISecret   = "<CCLOUD_SR_API_SECRET>"
    )
    
    func main() {
    
        topic := "go-test-topic"
        createTopic(topic)
    
        // Produce a new record to the topic...
        producer, err := kafka.NewProducer(&kafka.ConfigMap{
            "bootstrap.servers": bootstrapServers,
            "sasl.mechanisms":   "PLAIN",
            "security.protocol": "SASL_SSL",
            "sasl.username":     ccloudAPIKey,
            "sasl.password":     ccloudAPISecret})
    
        if err != nil {
            panic(fmt.Sprintf("Failed to create producer: %s", err))
        }
    
        client, err := schemaregistry.NewClient(schemaregistry.NewConfigWithAuthentication(
            schemaRegistryAPIEndpoint,
            schemaRegistryAPIKey,
            schemaRegistryAPISecret))