SSE (Server Sent Event)

SSE support is an extension to the HTTP DSL, whose entry point is the sse(requestName: Expression[String]) method.

Common operations

If you want to deal with several SSE streams per virtual users, you have to give them a name and pass this name on each SSE operation:

sseName(name: String)

For example:

sse("SSE Operation").sseName("myCustomName")

Of course, this step is not required if you deal with one single SSE stream per virtual user.


The first thing is to get a server sent event:

open(url: Expression[String])

For example:

exec(sse("Get SSE").open("/stocks/prices"))


Gatling automatically sets Accept header to text/event-stream and Cache-Control to no-cache.


When you’re done with a SSE stream, you can close it:


For example:

exec(sse("Close SSE").close())

Server Messages: Checks

Dealing with incoming messages from the server is done with checks, passed with the usual check() method.

Gatling currently only support one check at a time per SSE stream.

Set a Check

Checks can be set in 2 ways.

First, when sending a message:

exec(sse("Get SSE").open("/stocks/prices").check(myCheck))

Then, directly from the main HTTP flow:

exec(sse("Set Check").check(myCheck))

If a check was already registered on the server sent event at this time, it’s considered as failed and replaced with the new one.

Cancel a Check

One can decide to cancel a pending check:

exec(sse("Cancel Check").cancelCheck)

Build a Check

Now, to the matter at heart, how to build a server sent event check.

SSE support uses the same checks as WebSockets. So, please refer to the WebSocket section Build a Check for more details.

Here are few examples:


  .check(wsListen.within(30 seconds).expect(1)))


One complex thing is that, when using non blocking checks that save data, state is stored in a different flow than the main one.

So, one has to reconciliate the main flow state and the WebSocket flow one.

This can be done:

  • implicitly when performing an action on the WebSocket from the main flow, such as send a message to the server
  • explicitly with the reconciliate method.
exec(ws("Reconciliate states").reconciliate)


Server sent event support uses the same parameter as the HttpProtocol:

baseURL(url: String): serves as root that will be prepended to all relative server sent event urls

baseURLs(urls: String*): serves as round-robin roots that will be prepended to all relative server sent event urls


Here’s an example that runs against a stock market sample:

val httpConf = http

val scn = scenario("Server Sent Event")
  .exec(sse("Close SSE").close())