Record a Kafka script
You can record a Kafka protocol script in VuGen to monitor the health of your Kafka deployment.
Record a Kafka script
Configure the necessary settings and record a Kafka protocol script in VuGen.
To record a Kafka script:
-
Prerequisites:
- Before working with Kafka scripts, make sure your Java environment is set up. For details, see Set up the environment for Java protocols.
- You must have a working Kafka broker.
- You must have a configuration file in VuGen for the Kafka consumer, containing the mandatory configuration properties. If you have not created or imported a configuration file in VuGen, see Consumer configuration.
-
In VuGen, create a new Kafka protocol script. The Kafka script template opens in the VuGen editor.
-
(Optional) Set the code generation options for the script, using the Kafka > Code Generation node of the recording options:
-
Choose where the producer configuration code is saved. By default, the producer configuration code is saved in the script file.
Note: After you record the script, you need to locate the producer configuration code and modify it in order to replay the script.
-
Enable VuGen to insert a consumer instance at the end of the script, if relevant. This consumer's purpose is to poll for all records sent by the producer during replay. This consumer can also be set to commit these records. If the records are committed, they are not consumed again by any subsequent consumers that poll for records.
-
-
Click the Record button in the VuGen toolbar. The Start Recording dialog box opens.
-
In the Configuration dropdown, select the configuration file for the consumer.
-
In the Topics field, add the Kafka topics to which the consumer subscribes.
-
Click Start Recording and record the script.
-
After you finish recording, modify the producer configuration. For details, see Producer configuration.
Producer and consumer configuration
VuGen's Kafka protocol provides an encapsulated producer and consumer per Vuser. The producer and consumer configurations are each set at different stages of recording the script.
The consumer is configured based on a configuration file that you create and select before you begin recording. You must include certain properties in the configuration file to record a script. Consumer configuration files created or imported in VuGen are saved, and can be reused for later Kafka recordings.
To create a configuration file:
- Open a Kafka script.
- In the VuGen toolbar, select Record > Recording Options.
- Use the Kafka > Configuration Files node of the recording options to create a configuration file. For details, see Kafka > Configuration Files.
When you record a script, the producer is configured automatically based on shared properties copied from the consumer configuration. After you finish recording, you modify the producer configuration to define certain mandatory properties. You must define these properties for the producer in order to replay the script. You can also add or modify other properties as needed.
You can modify the producer configuration in two ways:
- Insert the LrKafkaProducer.reconfigureProducer API into the recorded script. For details, see Kafka Functions in the Function Reference.
-
Manually edit the code that defines the producer configuration. By default, this code is located in the recorded Kafka script. However, depending on the code generation settings used when the script was recorded, the code may be located in a .properties file saved in the same folder as the script.
For details on the mandatory properties, shared properties, and other properties available for producer and consumer configuration, see Kafka consumer and producer properties.
See also: