Step 3: Producing data

Producing data

Preparations

For this produce example, we’ll be using Git, Maven, Java 11 and an IDE which can build maven and compile Java projects, like Eclipse, IntelliJ Idea, etc.

It’s ok if you have a newer java version.

Make sure all the above are available before proceeding.

Installing them is out of scope for this guide.

Get the code

Clone the Axual open-source Java examples repository.

git clone https://gitlab.com/axual/public/client-java-examples.git
cd client-java-examples

Build the project

mvn clean install

Along with downloading resources and compiling the .java files into classes, you also just generated additional classes, but from AVRO source files. You can see them in the target/generated-sources/avro directory.

AVRO is an advanced data serialization system. You will see it more often in Axual’s user documentation. You can read more about it here.

Update the configuration

Open this maven project in your Java IDE.

  1. Open the src/main/java/io/axual/examples/util/config/impl/HelmConfiguration.java file for editing.
    Update the following fields: TENANT_HELM, INSTANCE_HELM.
    The values you need to replace those with are the shortnames of those entities as they are seen on the Self Service portal.

    You can also fetch both the Tenant and Instance values from the "environments" page in self-service:

    • Go to the Environments page in the self-service portal

    • Click the environment you are using (e.g. "default").

    • In that detailed overview, check the "Instance" field: its value is the TENANT-INSTANCE tuple ("tenant" "dash" "instance").

  2. Open the src/main/java/io/axual/examples/util/config/Configuration.java file for editing.
    Update the following fields: SASL_USERNAME, SASL_PASSWORD.
    The SASL_USERNAME and SASL_PASSWORD values are the credentials you generated in the previous step. Copy them from the file you temporarily stored them in, and paste them in the configuration class.

  3. Truststore update: Your essentials-package should contain a JKS-formatted truststore file, along with other key-material. Copy your truststore file and paste it inside the client-java-examples repository, at src/main/resources/client-certs/axual.client.truststore.jks, replacing the existing truststore.

That’s it! You are now ready to run the SASL examples.

Run the producer

We’ll be using AVRO to serialize events.

We’ll focus on the examples in the src/main/java/io/axual/examples/kafka/sasl directory.

Running the producer from the command line is a little more complicated: it’s easier to simply run the main method from your IDE.

Open the KafkaClientSASLAvroProducer.java and run the main method. Check the logs: you should see successful produce messages.

Optional

If you performed the optional parts in the previous steps, you may also run the KafkaClientSASLStringProducer.java now, in order to produce string-formatted events to a different topic.

There is a second string-producer example: in the KafkaClientSASLTransactionalStringProducer.java file. This example illustrates another advanced use-case: transactional producing.

Next Step: Consuming data