Connecting to Apache Kafka® in Aiven
In this tutorial
Nussknacker allows creating decision scenarios on real-time data. As one way to ingest your data, you can connect directly to your Kafka and Schema Registry to read events from and write to your topics.
In this tutorial, we will explain how to connect to the Aiven from the Nussknacker Cloud and use a managed Apache Kafka as the input and output from Nussknacker.
Prerequisites
We assume that:
- You have already created the Aiven Kafka cluster
- You have already created a Nussknacker Cloud account
Setting up Aiven
- Go to Aiven console and navigate to Kafka cluster console.
- Navigate to 'Connection information' and choose SASL as authentication method (while it's possible to authenticate using client certificates, it's a bit more complex)
- You'll need data from
Apache Kafka
andSchema Registry
sections, as shown below:
Setting up Nussknacker Cloud
-
Go to Nussknacker Cloud
-
Click
Create instance
on the left panel -
Choose your instance name or use autogenerated value
-
Choose
Existing Kafka cluster
-
Fill in the following fields
- Properties:
{
"bootstrap.servers": "xxx-project.aivencloud.com:18234",
"security.protocol": "SASL_SSL",
"sasl.jaas.config": "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"avnadmin\" password=\"xxxxx\";",
"sasl.mechanism": "PLAIN",
"ssl.truststore.type": "PEM",
"ssl.truststore.location": "/certs/client.truststore",
"schema.registry.url": "https://xxx-project.aivencloud.com:18234",
"basic.auth.credentials.source": "USER_INFO",
"basic.auth.user.info": "avnadmin:xxxx"
}Where:
bootstrap.servers
should beService URI
from Apache Kafka tabusername
should beUser
(avnadmin
by default) from Apache Kafka tabpassword
should bePassword
from Apache Kafka tabschema.registry.url
should containService URI
from Schema Registry tab, without user and passwordbasic.auth.user.info
should containUser
andPassword
from Schema Registry tab, separated with:
- Truststore: copy
CA Certificate
from Apache Kafka tab
-
Click submit button
-
Your Nussknacker instance connected to Aiven Kafka will be created within a couple of minutes
Creating a topic and a schema
- In the Aiven Kafka service go to
Topics
tab - Click the
Add topic
button and fill the needed fields - Your topic is created, now let
s define a data contract. Go to
Schemas` tab - Click the
Create schema
button, remember thatSubject
should be equal to created topic name plus-value
suffix - Choose your schema type, for now, Avro and JSON Schema are supported in Nussknacker Cloud
- Enter your schema
- Click the
Create
button
Creating a scenario
- Go to Nussknacker Cloud management
- Open your running Nussknacker instance with the
Open instance
button - Create your first scenario with the
Create scenario
button- Choose the preferred scenario name
- Drag and drop the
Kafka
source from the left panel - You should see your topic on the
Topic
drop-down list - Add custom logic like filtering, sending to some other
Kafka
sink - Press
deploy
button on the left - Wait a while until scenario will be deployed
Sending messages to and receiving messages from Nussknacker scenario
You can read about messaging with Nussknacker in the documentation.