This QuickStart assumes that you have created a StreamNative cluster with the Kafka protocol enabled, created a service account, and granted the service account
produce and consume permissions to a namespace for the target topic.Prerequisites
- Install Java 17. For details, see overview of JDK installation.
- Install Maven. For details, see installing Apache Maven.
Connect to your cluster using API keys
This section describes how to connect to your StreamNative cluster using the Kafka Java client with SASL/PLAIN authentication.Before you begin
- Before using an API key, verify that the service account is authorized to access the resources, such as tenants, namespaces, and topics.
- The password for different utilities as
kcatwill be equal totoken:<API KEY>.
Steps
-
Add Maven dependencies.
-
Open a terminal and run a Kafka consumer to receive a message from the
test-kafka-topictopic.SERVER-URL: the Kafka service URL of your StreamNative cluster.API-KEY: an API key of your service account.
-
Open another terminal and run a Kafka producer to send a message to the
test-kafka-topictopic.SERVER-URL: the Kafka service URL of your StreamNative cluster.API-KEY: an API key of your service account.
Connect to your cluster using OAuth2 authentication
This section describes how to connect to your StreamNative cluster using the Kafka Java client with OAuth2 authentication.Before you begin
-
Get the OAuth2 credential file.
- On the left navigation pane, click Service Accounts.
- In the row of the service account you want to use, in the Key File column, click the Download icon to download the OAuth2 credential file to your local directory.
-
Get the service URL of your StreamNative cluster.
- On the left navigation pane, in the Admin area, click Pulsar Clusters.
- Select the Details tab, and in the Access Points area, click Copy at the end of the row of the Kafka Service URL (TCP).
Steps
-
Add Maven dependencies.
-
Open a terminal and run a Kafka consumer to receive a message from the
test-topictopic.YOUR-KEY-FILE-ABSOLUTE-PATH: the path to your downloaded OAuth2 credential file.YOUR-KAFKA-SERVICE-URL: the Kafka service URL of your StreamNative cluster.YOUR-AUDIENCE-STRING: theaudienceparameter is a combination of theurn:sn:pulsar, your organization name, and your Pulsar instance name.
-
Open another terminal and run a Kafka producer to send a message to the
test-topictopic.YOUR-KEY-FILE-ABSOLUTE-PATH: the path to your downloaded OAuth2 credential file.YOUR-KAFKA-SERVICE-URL: the Kafka service URL of your StreamNative cluster.YOUR-AUDIENCE-STRING: theaudienceparameter is a combination of theurn:sn:pulsar, your organization name, and your Pulsar instance name.