Setting up Development Environment and Connecting Course Code to a Pulsar Cluster
Before we start building our e-commerce application, we need to setup our development environment and connect to the StreamNative Hosted Pulsar cluster. It is recommended to setup your development environment before the start of the course.
Setting up Development Environment
We suggest using Java 17 for the course (the Java Pulsar Admin Client may not work with Java 11). The source code is designed for use with Maven and we suggest using the free Community Edition of IntelliJ as your IDE. The following guides will help with setting up your Java+Maven+IntelliJ development environment. If you have any questions at all, do not hesitate to reach out to training-help@streamnative.io.
Connecting Course Code to a Pulsar Cluster
Now that your development environment is ready, let’s download the course code and test connectivity to a Pulsar cluster.
In the video, we import the downloaded code into IntelliJ and connect to a Pulsar Cluster.
- Make sure you have the OAuth2 security json file. If you are using a tenant in the StreamNative Training cluster, you will have been provided the json file. If you created your own StreamNative Hosted cluster, you should have downloaded the file after creating the service account.
- Download and unzip PulsarClassFiles.zip in a folder on your Desktop.
- Select Open in IntelliJ and select the unzipped PulsarClassFiles folder.
- Place the OAuth2 security json file in the PulsarClassFiles/Developer-Training/src/main/resources folder.
- Navigate to PulsarClassFiles/Developer-Training/src/main/java/sn_training/test_setup/TestSetup.java.
- Edit the following line in TestSetup.java to include the full path of the security json file provided to you. An example file path is as follows for Mac or Windows:
Mac:
private static String CREDENTIALS_URL = "file:///Users/dustinnest/Desktop/CourseFiles/PulsarClassFiles/Developer-Training/src/main/resources/o-mj3r8-student31-05032024.json";
Windows (note that there are SIX backslashes after "file:")
private static String CREDENTIALS_URL = "file:\\\\\\Users\\dustin.nest\\CourseFiles\\PulsarClassFiles\\PulsarClassFiles\\Developer-Training\\src\\main\\resources\\o-mj3r8-student31-05032024.json";
- Edit the following line in TestSetup.java to use your student id. Your student id is the name of your tenant on the cluster. The namespace is developer.
String topic = "persistent://student31/developer/test_setup";
- Open Terminal in IntelliJ and navigate to the Developer-Training folder. This folder contains the pom.xml file. Execute the mvn command below to compile and execute TestSetup.java as completed in the video:
cd Developer-Training
mvn compile exec:java@test_setup
Troubleshooting
If you see the following error, scroll up in terminal and you may notice the error “Unable to read private key”.
java.lang.NullPointerException: Cannot invoke "org.apache.pulsar.client.api.Producer.newMessage()" because "producer" is null
...
Caused by: org.apache.pulsar.client.api.PulsarClientException$AuthenticationException: Unable to read private key: /Users/dustinnest/Desktop/LabCode/LearnDashStarterCode/PulsarClassFiles/Developer-Training/src/main/resources/o-mj3r8-student38-06282024.json (No such file or directory)
java.lang.NullPointerException: Cannot invoke "org.apache.pulsar.client.api.Producer.newMessage()" because "producer" is null
This indicates the path to your json file is incorrect and the producer could not be created. The Exception isn’t caught in the existing code sample resulting in a null error later in the code. You will need to determine the correct path to the json file for your development environment.
Reminder: If you need any help, email training-help@streamnative.io.
