Connecting to Protocol Handler with JWT

In the following exercise, we connect a Kafka application that uses transactions to a StreamNative Hosted Pulsar cluster using a JWT Token. The video demonstrates this using a client.properties file.

The example uses the following code:

  • KSN-Training/src/main/java/sn_training/Transactions/KProducerTransactions.java
  • KSN-Training/src/main/java/sn_training/Transactions/KConsumer.java
  • KSN-Training/src/main/java/sn_training/resources/client.properties.transactions

For an example configuring the connection with a JWT Token directly in the Java code, see TransactionsV2.


Update client.properties.transactions file so topic1 and topic2 use your student id (e.g. kafkastudent3-transactions1 and kafkastudent3-transactions2). With Pulsar, the topic will be automatically created for you. You are currently using the public/default tenant/namespace shared by all students. Using your student id in the topic name will ensure you don’t access a topic used by another student. We will discuss multi-tenancy later.

Make the following changes to client.properties.transactions to convert your application to connect to the Pulsar cluster:

  • edit bootstrap.servers to point to the Kafka endpoint on port 9093
  • edit sasl.jaa.config password to be “token:<JWT TOKEN>”, the token was provided to you via email if you are using our training cluster

Please reference Transactions2 if you would like an example of configuring producing and consuming Kafka messages directly in the Java code.


Now that we’ve produced and consumed our first messages, we should at least mention message retention in Pulsar. Message retention in Pulsar works differently than Kafka, and message retention when using Kafka with consumer groups works differently than if messages were consumed by a Pulsar consumer using subscriptions. We’ve included the following optional video if you would like to learn more about message retention with Kafka on a StreamNative cluster.