Kafka protocol (manual)

VuGen's Kafka protocol enables you to create a Java Vuser script to monitor the health of your Kafka deployment by collecting Kafka-specific metrics, including producer and consumer metrics.

Apache Kafka overview

Apache Kafka is an event-streaming platform that provides unified, high-throughput, low-latency data feeds. It is often used to pass messages between microservices and software components.

Kafka is a distributed system consisting of servers and clients that communicate via a high-performance TCP network protocol. Two types of client applications are producers and consumers:

  • Producers publish (write) events to Kafka.

  • Consumers subscribe to (read and process) events in Kafka.

For more details, see https://kafka.apache.org/.

Back to top

Kafka protocol scripts

The Kafka protocol supports scripting in Java, using standard Java conventions. You manually insert your code into the script using the VuGen editor.

Producer and consumer

The Kafka protocol provides an encapsulated producer and consumer per Vuser. These must be initialized at the beginning of the Vuser script, in the init method. For details, see Script classes and methods.

APIs

VuGen provides Kafka-specific functions for Kafka scripts. These functions are all static methods of the LrKafkaProducer and LrKafkaConsumer classes, which must be initialized for each Vuser. For details, see Kafka Functions in the Function Reference.

In addition to the Kafka-specific APIs, all standard Java methods are supported in Kafka scripts.

Note that when you create a new Kafka script, the import lrapi.lr class is already inserted into the script template.

Script classes and methods

When working with this type of Vuser script, you place all your code in the Actions class, which is displayed when the script template opens. The Actions class contains three methods: init, action, and end.

The following table shows what to include in each method and when each method is executed:

Script method
Is executed when...
Details
init
the Vuser is initialized

This method emulates a login to a server and is executed only once. Place all login procedures and one-time configuration settings here, including initializing the producer and consumer.

Example: Inserting the following lines in the init method initializes the producer and consumer using the login properties of the specified file:

LrKafkaConsumer.initConsumer(“\\any.domain.net\KafkaConfigs\consumer.properties”);

LrKafkaProducer.initProducer(“\\any.domain.net\KafkaConfigs\producer.properties”);

action
the Vuser is in "Running" status
This method emulates client activity, and is executed according to the number of iterations you set in the runtime settings. Place all Vuser actions here.
end
the Vuser finishes or is stopped

This method emulates a log off procedure and is executed only once. Place all procedures you want the Vuser to execute at the end of the script here, including closing the producer and consumer, and deallocating any resources used during the script.

Example: Inserting the following lines into the end method closes the producer and consumer:

LrKafkaConsumer.closeConsumer();

LrKafkaProducer.closeProducer();

For details on creating a Kafka script, see Manually create a Kafka script.

Back to top

See also: