使用SASL用户名和密码的Confluent Cloud的Kafka消费者的Go客户端示例。

huangapple go评论119阅读模式
英文:

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

问题

有人有一个使用sasl.username和sasl.password的Kafka消费者的confluent cloud的go客户端示例吗?

我在尝试从confluent cloud消费消息时遇到了一个错误。

  1. 连接到Kafka代理失败:kafka:客户端已经用完了可用的代理来进行通信:EOF
英文:

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.

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

答案1

得分: 0

Confluent有自己的示例代码存储库。

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

提取:

  1. bootstrapServers = "<BOOTSTRAP_SERVERS>"
  2. ccloudAPIKey = "<CCLOUD_API_KEY>"
  3. ccloudAPISecret = "<CCLOUD_API_SECRET>"
  4. schemaRegistryAPIEndpoint = "<CCLOUD_SR_ENDPOINT>"
  5. schemaRegistryAPIKey = "<CCLOUD_SR_API_KEY>"
  6. schemaRegistryAPISecret = "<CCLOUD_SR_API_SECRET>"
  7. )
  8. func main() {
  9. topic := "go-test-topic"
  10. createTopic(topic)
  11. // Produce a new record to the topic...
  12. producer, err := kafka.NewProducer(&kafka.ConfigMap{
  13. "bootstrap.servers": bootstrapServers,
  14. "sasl.mechanisms": "PLAIN",
  15. "security.protocol": "SASL_SSL",
  16. "sasl.username": ccloudAPIKey,
  17. "sasl.password": ccloudAPISecret})
  18. if err != nil {
  19. panic(fmt.Sprintf("Failed to create producer: %s", err))
  20. }
  21. client, err := schemaregistry.NewClient(schemaregistry.NewConfigWithAuthentication(
  22. schemaRegistryAPIEndpoint,
  23. schemaRegistryAPIKey,
  24. schemaRegistryAPISecret))
英文:

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

  1. bootstrapServers = &quot;&lt;BOOTSTRAP_SERVERS&gt;&quot;
  2. ccloudAPIKey = &quot;&lt;CCLOUD_API_KEY&gt;&quot;
  3. ccloudAPISecret = &quot;&lt;CCLOUD_API_SECRET&gt;&quot;
  4. schemaRegistryAPIEndpoint = &quot;&lt;CCLOUD_SR_ENDPOINT&gt;&quot;
  5. schemaRegistryAPIKey = &quot;&lt;CCLOUD_SR_API_KEY&gt;&quot;
  6. schemaRegistryAPISecret = &quot;&lt;CCLOUD_SR_API_SECRET&gt;&quot;
  7. )
  8. func main() {
  9. topic := &quot;go-test-topic&quot;
  10. createTopic(topic)
  11. // Produce a new record to the topic...
  12. producer, err := kafka.NewProducer(&amp;kafka.ConfigMap{
  13. &quot;bootstrap.servers&quot;: bootstrapServers,
  14. &quot;sasl.mechanisms&quot;: &quot;PLAIN&quot;,
  15. &quot;security.protocol&quot;: &quot;SASL_SSL&quot;,
  16. &quot;sasl.username&quot;: ccloudAPIKey,
  17. &quot;sasl.password&quot;: ccloudAPISecret})
  18. if err != nil {
  19. panic(fmt.Sprintf(&quot;Failed to create producer: %s&quot;, err))
  20. }
  21. client, err := schemaregistry.NewClient(schemaregistry.NewConfigWithAuthentication(
  22. schemaRegistryAPIEndpoint,
  23. schemaRegistryAPIKey,
  24. schemaRegistryAPISecret))

huangapple
  • 本文由 发表于 2023年2月22日 01:58:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75524211.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定