Project Setup

Learn how to set up your project to use the Gatling gRPC protocol

Under the hood, Gatling uses gRPC-Java to implement its protocol support.

Understand the license and limitations

The Gatling gRPC component is distributed under the Gatling Enterprise Component License.

The Gatling gRPC protocol can be used with both the Community Edition and Enterprise versions of Gatling.

Its usage is unlimited when running tests on Gatling Enterprise. When used with Gatling Community Edition, usage is limited to:

  • 5 users maximum
  • 5 minute duration tests

Limits after which the test will stop. This means that all locally executed tests using the gRPC protocol are limited by these values. When the test stops, Gatling logs which limit it exceeded.

Get started with the demo project

A demo project is available for each supported language and build tool:

It also contains a demo server that you can use if you want to run the example scenarios over a working server.

Add the Gatling gRPC dependency

The Gatling gRPC plugin isn’t included with Gatling by default. Add the Gatling gRPC dependency, in addition to the usual Gatling dependencies.

The Gatling gRPC plugin was introduced in Gatling 3.10 and isn’t compatible with older versions.

For Java or Kotlin:

<dependencies>
  <dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-grpc-java</artifactId>
    <version>3.16.1</version>
    <scope>test</scope>
  </dependency>
</dependencies>

Base Gatling setup for Maven is documented here.

dependencies {
  gatlingImplementation("io.gatling:gatling-grpc-java:3.16.1")
}

Base Gatling setup for Gradle is documented here.

For JavaScript/TypeScript:

npm install @gatling.io/grpc@3.16.102

For Scala:

<dependencies>
  <dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-grpc</artifactId>
    <version>3.16.1</version>
    <scope>test</scope>
  </dependency>
</dependencies>

Base Gatling setup for Maven is documented here.

dependencies {
  gatlingImplementation("io.gatling:gatling-grpc:3.16.1")
}

Base Gatling setup for Gradle is documented here.

libraryDependencies += "io.gatling" % "gatling-grpc" % "3.16.1" % "test,it"

Base Gatling setup for sbt is documented here.

Configure Protobuf code generation

By default, gRPC uses Protocol Buffers (protobuf) to serialize messages. The following sections show typical configurations to generate your gRPC method descriptors and data access classes from proto files. If your gRPC service uses something else, for example JSON messages, adapt the configuration to your use case.

Protobuf for Java

For a project running Java with either Maven or Gradle:

<build>
  <plugins>
    <plugin>
      <groupId>io.github.ascopes</groupId>
      <artifactId>protobuf-maven-plugin</artifactId>
      <version>${protobuf-maven-plugin.version}</version>
      <executions>
        <execution>
          <goals>
            <goal>generate-test</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <protocVersion>${protobuf.version}</protocVersion>
        <binaryMavenPlugins>
          <binaryMavenPlugin>
            <groupId>io.grpc</groupId>
            <artifactId>protoc-gen-grpc-java</artifactId>
            <version>${grpc.version}</version>
            <!-- Avoid dependency on javax.annotation-api -->
            <options>@generated=omit</options>
          </binaryMavenPlugin>
        </binaryMavenPlugins>
      </configuration>
    </plugin>
  </plugins>
</build>

With the following properties:

<properties>
  <grpc.version>1.75.0</grpc.version>
  <protobuf.version>4.32.1</protobuf.version>
  <protobuf-maven-plugin.version>3.9.1</protobuf-maven-plugin.version>
</properties>

Add your proto files in the src/test/proto directory.

Check the demo project for a full example: Gatling gRPC Java demo with Maven.

plugins {
  id("idea")
  id("java")
  id("com.google.protobuf") version "0.9.5"
}

protobuf {
  protoc {
    artifact = "com.google.protobuf:protoc:4.32.1"
  }
  plugins {
    grpc {
      artifact = "io.grpc:protoc-gen-grpc-java:1.75.0"
    }
  }
  generateProtoTasks {
    ofSourceSet("gatling").forEach { task ->
      compileGatlingJava.dependsOn(task)
      task.plugins {
        grpc {}
      }
    }
  }
}

You will also need to add the generated files to the idea module and Gatling source sets:

var generatedSources = [
  file("${protobuf.generatedFilesBaseDir}/gatling/java"),
  file("${protobuf.generatedFilesBaseDir}/gatling/grpc")
]

idea {
  module {
    generatedSources.forEach { generatedSourceDirs += it }
  }
}

sourceSets {
  gatling {
    java {
      generatedSources.forEach { srcDirs += it }
    }
  }
}

Add your proto files in the src/gatling/proto directory.

Check the demo project for a full example: Gatling gRPC Java demo with Gradle.

Protobuf for JavaScript and TypeScript

Add your proto files in the protobuf directory.

Check the demo project for full examples:

Protobuf for Kotlin

For a project running Kotlin with either Maven or Gradle:

<build>
  <plugins>
    <plugin>
      <groupId>io.github.ascopes</groupId>
      <artifactId>protobuf-maven-plugin</artifactId>
      <version>${protobuf-maven-plugin.version}</version>
      <executions>
        <execution>
          <goals>
            <goal>generate-test</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <protocVersion>${protobuf.version}</protocVersion>
        <binaryMavenPlugins>
          <binaryMavenPlugin>
            <groupId>io.grpc</groupId>
            <artifactId>protoc-gen-grpc-java</artifactId>
            <version>${grpc.version}</version>
            <!-- Avoid dependency on javax.annotation-api -->
            <options>@generated=omit</options>
          </binaryMavenPlugin>
        </binaryMavenPlugins>
      </configuration>
    </plugin>
  </plugins>
</build>

With the following properties:

<properties>
  <grpc.version>1.75.0</grpc.version>
  <kotlin.version>2.2.20</kotlin.version>
  <protobuf.version>4.32.1</protobuf.version>
  <protobuf-maven-plugin.version>3.9.1</protobuf-maven-plugin.version>
</properties>

Add your proto files in the src/test/proto directory.

Check the demo project for a full example: Gatling gRPC Kotlin demo with Maven.

plugins {
  idea
  kotlin("jvm")
  kotlin("plugin.allopen")

  id("com.google.protobuf") version "0.9.5"
}

dependencies {
  gatlingApi("com.google.protobuf:protobuf-kotlin:4.32.1")
}

protobuf {
  protoc {
    artifact = "com.google.protobuf:protoc:4.32.1"
  }
  plugins {
    create("grpc") {
      artifact = "io.grpc:protoc-gen-grpc-java:1.75.0"
    }
  }
  generateProtoTasks {
    ofSourceSet("gatling").forEach { task ->
      tasks.getByName("compileGatlingKotlin").dependsOn(task)
      task.builtins {
        maybeCreate("java") // Used by kotlin and already defined by default
        create("kotlin")
      }
      task.plugins {
        create("grpc")
      }
    }
  }
}

You will also need to add the generated files to the idea module and Gatling source sets:

var generatedSources = arrayOf(
  file("${protobuf.generatedFilesBaseDir}/gatling/java"),
  file("${protobuf.generatedFilesBaseDir}/gatling/kotlin"),
  file("${protobuf.generatedFilesBaseDir}/gatling/grpc")
)

idea {
  module {
    generatedSourceDirs.plusAssign(generatedSources)
  }
}

sourceSets.getByName("gatling") {
  java.srcDirs(generatedSources)
  kotlin.srcDirs(generatedSources)
}

Add your proto files in the src/gatling/proto directory.

Check the demo project for a full example: Gatling gRPC Kotlin demo with Gradle.

Protobuf for Scala

For an sbt project running Scala, add the ScalaPB plugin in project/plugins.sbt:

addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.8")

libraryDependencies ++= Seq(
  "com.thesamet.scalapb" %% "compilerplugin" % "0.11.20"
)

And configure it in your project settings (build.sbt):

val commons = Seq(
  PB.protocVersion := "4.32.1" // scalapb.compiler.Version.protobufVersion may point to an older version
)

val scalaSettings: Seq[Def.Setting[_]] = commons ++ Seq(
  Test / PB.targets := Seq(
    scalapb.gen() -> (Test / sourceManaged).value
  ),
  libraryDependencies ++= Seq(
    "com.thesamet.scalapb" %% "scalapb-runtime"      % scalapb.compiler.Version.scalapbVersion % "protobuf",
    "com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion % "test"
  )
)

scalaSettings

Use javaSettings instead if you would rather use POJOs instead of objects generated by ScalaPB:

val javaSettings: Seq[Def.Setting[_]] = commons ++ Seq(
  Test / PB.targets := Seq(
    PB.gens.java -> (Test / sourceManaged).value,
    PB.gens.plugin("grpc-java") -> (Test / sourceManaged).value
  ),
  libraryDependencies ++= Seq(
    ("io.grpc" % "protoc-gen-grpc-java" % scalapb.compiler.Version.grpcJavaVersion).asProtocPlugin()
  )
)

javaSettings

Add your proto files to the src/test/protobuf directory.

Check the demo project for a full example: Gatling gRPC Scala demo with sbt.

Edit this page on GitHub