Go client example for kafka consumer of Fusion Cloud with sasl.username and sasl.password

WBOY
Release: 2024-02-10 21:27:08
forward
1021 people have browsed it

具有 sasl.username 和 sasl.password 的融合云的 kafka 消费者的 go 客户端示例

php editor Baicao brings you a Go client example of Fusion Cloud Kafka consumer with sasl.username and sasl.password. In this example, we will show how to use the Go programming language to create a consumer client capable of secure authentication with Fusion Cloud Kafka. By setting the correct sasl.username and sasl.password parameters, we can ensure that the client can successfully connect and consume messages from the Kafka topic. This example details the required libraries and code to help you quickly understand and apply this functionality. Let’s take a look!

Question content

Does anyone have a go client example of a kafka consumer using sasl.username and sasl.password?

I'm getting an error when trying to consume messages from Fusion Cloud.

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

Solution

confluence has its own sample repository

https://github.com /confluenceinc/confluence-kafka-go/blob/master/examples/confluence_cloud_example/confluence_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))
Copy after login

The above is the detailed content of Go client example for kafka consumer of Fusion Cloud with sasl.username and sasl.password. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!