Gatling Kafka Plugin

Build Maven Central Scala Steward badge codecov.io

Introduction

Plugin to support Kafka in Gatling (3.9.x)

Usage

Getting Started

Plugin is currently available for Scala 2.13, Java 17, Kotlin.

You may include plugin as dependency in project with your tests. Write

Scala

libraryDependencies += "org.galaxio" %% "gatling-kafka-plugin" % <version> % Test

Java

Write this to your dependencies block in build.gradle:

gatling "org.galaxio:gatling-kafka-plugin_2.13:<version>"

Kotlin

Write this to your dependencies block in build.gradle:

gatling("org.galaxio:gatling-kafka-plugin_2.13:<version>")

Example Scenarios

Scala

Examples here

Java

Examples here

Kotlin

Examples here

Download and create Avro schema

Avro schema is downloaded using the plugin sbt-schema-registry-plugin and for that you need to configure schemas and url in build.sbt and run the command:

sbt schemaRegistryDownload

To create java classes you should add use capabilities, that provide plugin sbt-avro. This plugin is included in project and will do all needed for creating java classes in compile stage. To run you should create scala object in root project directory and type sbt run.

Example download avro-schema

Example here

Avro support in Request-Reply

Scala

To use avro messages as payload in key or value, you must:

  • define implicit for schema registry url:
implicit val schemaRegUrl: String = "http://localhost:9094"
  • or define serde for your class:
val ser =
  new KafkaAvroSerializer(
    new CachedSchemaRegistryClient("schRegUrl".split(',').toList.asJava, 16),
  )

val de =
  new KafkaAvroDeserializer(
    new CachedSchemaRegistryClient("schRegUrl".split(',').toList.asJava, 16),
  )

implicit val serdeClass: Serde[MyAvroClass] = new Serde[MyAvroClass] {
  override def serializer(): Serializer[MyAvroClass] = ser.asInstanceOf[Serializer[MyAvroClass]]
  override def deserializer(): Deserializer[MyAvroClass] = de.asInstanceOf[Deserializer[MyAvroClass]]
}

Java

To use avro messages as payload in key or value, you must define serde for your class:

public static Serializer<MyAvroClass> ser = (Serializer) new KafkaAvroSerializer(new CachedSchemaRegistryClient(Arrays.asList("schRegUrl".split(",")), 16));
public static Deserializer<MyAvroClass> de = (Deserializer) new KafkaAvroDeserializer(new CachedSchemaRegistryClient(Arrays.asList("schRegUrl".split(",")), 16));

Kotlin

To use avro messages as payload in key or value, you must define serde for your class:

val ser = KafkaAvroSerializer(CachedSchemaRegistryClient("schRegUrl".split(','), 16),) as Serializer<MyAvroClass>
val de = KafkaAvroDeserializer(CachedSchemaRegistryClient("schRegUrl".split(','), 16),) as Deserializer<MyAvroClass>

Example usage Avro in Request-Reply

Example scala

Example java

Example kotlin