SSE support is an extension to the HTTP DSL, whose entry point is the
sse(requestName: Expression[String]) method.
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:
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:
Gatling automatically sets
Accept header to
When you’re done with a SSE stream, you can close it:
Server Messages: Checks¶
Dealing with incoming messages from the server is done with checks, passed with the usual
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:
Then, directly from the main HTTP flow:
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:
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:
exec(sse("sse").open("/stocks/prices") .check(wsAwait.within(10).until(1).regex(""""event":"snapshot(.*)""""))) exec(sse("sse").open("/stocks/prices") .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
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 .baseURL("http://localhost:8080/app") val scn = scenario("Server Sent Event") .exec( sse("Stocks").open("/stocks/prices") .check(wsAwait.within(10).until(1).regex(""""event":"snapshot(.*)""""))) .pause(15) .exec(sse("Close SSE").close())