Record a Kafka script

You can record a Kafka protocol script in VuGen to monitor the health of your Kafka deployment.

Recording Kafka scripts is available from VuGen 2022 R1.

Record a Kafka script

Configure the necessary settings and record a Kafka protocol script in VuGen.

To record a Kafka script:

  1. 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.
  2. In VuGen, create a new Kafka protocol script. The Kafka script template opens in the VuGen editor.

  3. (Optional) Set the code generation options for the script, using the Kafka > Code Generation node of the recording options:

    1. 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 will need to locate the producer configuration code and modify it in order to replay the script.

    2. 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 will not be consumed again by any subsequent consumers that poll for records.

  4. Click the Record button in the VuGen toolbar. The Start Recording dialog box opens.

  5. In the Configuration dropdown, select the configuration file for the consumer.

  6. In the Topics field, add the Kafka topics to which the consumer will subscribe.

  7. Click Start Recording and record the script.

  8. After you finish recording, modify the producer configuration. For details, see Producer configuration.

Back to top

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.

Consumer configuration

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:

  1. Open a Kafka script.
  2. In the VuGen toolbar, select Record > Recording Options.
  3. Use the Kafka > Configuration Files node of the recording options to create a configuration file. For details, see Kafka > Configuration Files.

Producer configuration

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.

Back to top

See also: