英文:
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消费消息时遇到了一个错误。
连接到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.
Failed to connect to Kafka broker: kafka: client has run out of available brokers to talk to: EOF
答案1
得分: 0
Confluent有自己的示例代码存储库。
提取:
	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))
英文:
Confluent has their own repo for examples
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))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论