https://github.com/galax-io/gatling-kafka-plugin
Gatling protocol plugin for supporting Kafka.
https://github.com/galax-io/gatling-kafka-plugin
gatling kafka performance performance-testing
Last synced: 15 days ago
JSON representation
Gatling protocol plugin for supporting Kafka.
- Host: GitHub
- URL: https://github.com/galax-io/gatling-kafka-plugin
- Owner: galax-io
- License: apache-2.0
- Created: 2023-10-24T04:17:59.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-22T23:23:19.000Z (over 1 year ago)
- Last Synced: 2024-05-22T23:46:51.756Z (over 1 year ago)
- Topics: gatling, kafka, performance, performance-testing
- Language: Scala
- Homepage:
- Size: 102 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- trackawesomelist - gatling-kafka-plugin (⭐8) - Plugin for support Kafka in Gatling. (Recently Updated / [Oct 07, 2024](/content/2024/10/07/README.md))
- awesome-gatling - gatling-kafka-plugin - Plugin for support Kafka in Gatling. (Tools / Plugins)
README
# Gatling Kafka Plugin
 [](https://search.maven.org/search?q=org.galaxio.gatling-kafka) [](https://scala-steward.org)
[](https://codecov.io/github/galax-io/gatling-kafka-plugin?branch=master)
# Introduction
Plugin to support Kafka in Gatling (3.9.x)+
| Gatling Version | Kafka Plugin Version | Notable Changes |
|-----------------|-----------------------|-------------------------------------------------------------------------------------------------------------|
| 3.9.x - 3.11.x | Releases up to 0.15.1 | May require additional akka dependency in your dependencies - e.g. com.typesafe.akka:akka-actor_2.13:2.6.20 |
| 3.13.x | Releases after 0.15.1 | Akka dependency no longer required |
# Usage
### Getting Started
This plugin is currently available for Scala 2.13 / Java 17 / Kotlin.
To use it, you should include it as a dependency in your gatling project with your tests.
To include:
### Scala
```scala
libraryDependencies += "org.galaxio" %% "gatling-kafka-plugin" % % Test
```
### Java
Add this to your dependencies block in build.gradle:
```java
gatling "org.galaxio:gatling-kafka-plugin_2.13:"
```
### Kotlin
Add this to your dependencies block in build.gradle:
```kotlin
gatling("org.galaxio:gatling-kafka-plugin_2.13:")
```
## Example Scenarios
### Scala
Examples [here](src/test/scala/org/galaxio/gatling/kafka/examples)
### Java
Examples [here](src/test/java/org/galaxio/gatling/kafka/javaapi/examples)
### Kotlin
Examples [here](src/test/kotlin/org/galaxio/gatling/kafka/javaapi/examples)
## Download and create Avro schema
Avro schema is downloaded using the
plugin [sbt-schema-registry-plugin](https://github.com/galax-io/sbt-schema-registry-plugin)
and for that you need to configure schemas and url in `build.sbt` and run the command:
```bash
sbt schemaRegistryDownload
```
To create java classes you should add use capabilities, that provide plugin [sbt-avro](https://github.com/sbt/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](https://github.com/galax-io/gatling-kafka-plugin/tree/master/src/test/scala/org/galaxio/gatling/kafka/examples)
## Avro support in Request-Reply
### Scala
To use avro messages as payload in key or value, you must:
- define implicit for schema registry url:
```scala
implicit val schemaRegUrl: String = "http://localhost:9094"
```
- or define serde for your class:
```scala
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:
```java
public static Serializer ser = (Serializer) new KafkaAvroSerializer(new CachedSchemaRegistryClient(Arrays.asList("schRegUrl".split(",")), 16));
public static Deserializer 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:
```kotlin
val ser = KafkaAvroSerializer(CachedSchemaRegistryClient("schRegUrl".split(','), 16),) as Serializer
val de = KafkaAvroDeserializer(CachedSchemaRegistryClient("schRegUrl".split(','), 16),) as Deserializer
```
### Example usage Avro in Request-Reply
Example [scala](src/test/scala/org/galaxio/gatling/kafka/examples/AvroClassWithRequestReplySimulation.scala)
Example [java](src/test/java/org/galaxio/gatling/kafka/javaapi/examples/AvroClassWithRequestReplySimulation.java)
Example [kotlin](src/test/kotlin/org/galaxio/gatling/kafka/javaapi/examples/AvroClassWithRequestReplySimulation.kt)
### Build this plugin
When contributing to this project - check your build with:
```shell
sbt clean scalafmtCheckAll scalafmtSbtCheck compile coverage "Gatling / testOnly org.galaxio.gatling.kafka.examples.KafkaGatlingTest" test coverageOff
```
Reference to [ci.yml](/.github/workflows/ci.yml)