Connect to Aiven for Apache Kafka® with Go
Use Quick connect to set up a Go client for Aiven for Apache Kafka®. The guided flow helps you choose or create a topic, choose an authentication method, grant permissions, and copy generated producer and consumer code.
Prerequisites
- A running Aiven for Apache Kafka® service.
- A Go development environment.
- The
kafka-golibrary.
Open Quick connect
- In the Aiven Console, open your Aiven for Apache Kafka service.
- On the service Overview page, in the Set up your stream section, click Quick connect.
- At the top of the page, select Go in the language selector.
Step 1: Set up a topic
Topics organize and store the events that you stream to Apache Kafka.
-
In Topic name, do one of the following:
- Choose an existing topic.
- Click Create new topic, enter a name, and create the topic. The new topic is selected automatically for the next steps.
noteIf your service has Diskless topics enabled, you can create a Classic or Diskless topic, or choose an existing topic of either type. You can't change the topic type after creation. For more information, see Create Apache Kafka® topics.
Step 2: Set up an authentication method
-
Choose an authentication method:
-
SASL: Recommended. Use SASL/SCRAM-SHA-512 for username and password authentication.
Go code snippets use
SCRAM-SHA-512for SASL authentication.SASL is enabled by default for new Aiven for Apache Kafka services. For existing services, check whether SASL is enabled. If Enable SASL appears, click Enable SASL, then continue.
-
Client certificate: Use certificate-based authentication with mTLS instead of a password.
-
-
Select a service user:
- Select an existing service user from the list.
- To create one, click Create new service user, enter a username, and click Add service user.
-
Check the permission status shown for the selected user:
- If the user has all the required permissions, the granted permissions are
shown (for example,
read, write). To change them, click Manage access in ACLs. - If the user has some or no permissions, click Grant permissions. Select Produce, Consume, or both, and click Save.
noteThe
avnadminuser has permissions by default.For other service users, you can add permissions from Quick connect. To change or remove permissions, click Manage access in ACLs. For more information, see Manage Apache Kafka® ACLs.
- If the user has all the required permissions, the granted permissions are
shown (for example,
Step 3: Copy the code snippets
Download template is an optional shortcut for testing the connection without
a local Go environment. The ZIP file includes ready-to-run producer and consumer
code, certificates, and dependencies. To run it, follow the included README.md.
If you already have a Go project, copy the snippet from the Producer or
Consumer tab.
-
Under Prerequisites, initialize a Go module and install the required libraries:
go mod init <your-project-name>go get github.com/segmentio/kafka-goFor SASL, also install the SCRAM package:
go get github.com/segmentio/kafka-go/sasl/scram@v0.4.51 -
Under Downloads, download the certificate files for your authentication method:
- For SASL, click Download CA certificate.
- For Client certificate, click Download CA certificate, Download service certificate, and Download service access key.
The generated snippet loads the certificates directly, so you don't need to create a truststore.
-
Click the Producer or Consumer tab to view the generated producer or consumer code.
-
Copy the code.
For SASL, copied snippets include the service user password in plaintext. Store the code securely, and do not commit it to source control.
After you add the code to your project, update the certificate file paths to match where you saved the files, then run your producer or consumer to start streaming events.