SSE - How to listen to ALL the server response and print data till closing the connection

Hi,

I have SSE connection which will sending response every time interval specified (let say every 10 seconds) to the server. But when I try to checkMessage, Save and print the response after waiting for 60 seconds, I can see only one response printed in the console instead of 6. I have attached the code below for reference.

What should I modify in the code, so that I can print the sse response data every time interval(10 seconds) and close the sse connection after 60 min.

package TelemetryViewer
import io.gatling.commons.validation.Validation
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class test extends Simulation{

val headersLogin = Map(
“Content-Type” → “application/json”,
“Authorization” → “Basic YWRtaW46Tm9raWFOc3AxIQ==”
)

val headersCreateSubscription = Map(
“Content-Type” → “application/json”,
“Accept” → “application/json”
)

val httpProtocol = http
.baseUrl(“https://135.121.156.59”) // Here is the root for all relative URLs

val access_token = “”

val scn =
scenario(“Telemetry Viewer Load Testing”)
.exec(
http(“Get Access Token - POST “)
.post(”:443/rest-gateway/rest/api/v1/auth/token”)
.headers(headersLogin)
.body(StringBody(
“”"

{
“grant_type”: “client_credentials”
}""".stripMargin)).asJson
.check(status is 200)
.check(bodyString.saveAs(“resp_body”))
.check(jsonPath("$" ).saveAs(“RESPONSE_DATA” ))
.check(jsonPath("$.access_token").saveAs(“access_token”))
)

.exec(session => {
val response = session(“RESPONSE_DATA”).as[String]
println(s"LOGIN - RESPONSE BODY: \n$response")
val token = session(“access_token”).as[String]
println( s"ACCESS TOKEN - $token")
session
})

.exec(
http(“CREATE SUBSCRIPTION - POST”)
.post(":8619/telemetry-viewer/api/v1/restconf/data/nsp-telemetry-data-subscription:/subscriptions")
.header(“Content-Type” , “application/json”)
.header(“Authorization” , “Bearer “.concat(”${access_token}”))
.header(“Accept” , “application/json”)
.body(StringBody("""

{
“subscription”: [
{
“name”: “ap_2”,
“collection-interval”: 10,
“time-from”: 1600261668962,
“telemetry”: [
{
“id”: 0,
“type”: “telemetry:/base/interfaces/interface”
}
]
}
]
}""".stripMargin)).asJson
.check(jsonPath("$" ).saveAs(“CREATE_SUBSCRIPTION_RESPONSE_DATA” ))
)

.exec(session => {
val res = session(“CREATE_SUBSCRIPTION_RESPONSE_DATA”).as[String]
println(s"CREATE SUBSCRIPTION - RESPONSE BODY: \n$res")
session
})

.exec(
sse(“Telemetry Viewer Stats Streaming”)
.connect(":8619/telemetry-viewer/streams/telemetry/data/ap_2")
.header(“Accept” , “text/event-stream”)
.header(“Authorization” , “Bearer “.concat(”${access_token}”))
.await(60)(
sse.checkMessage(“Checking SSE: “).check(regex(”.dataEvent.”))
.check(bodyString.saveAs(“SSE_RESPONSE”))
)
)

.exec(
session => {
println("**** SSE DATA ****");
println(session(“SSE_RESPONSE”).as[String])
session
}
)

.exec(
sse(“sse_close”)
.close()
)

setUp(
scn.inject(atOnceUsers(1))
.protocols(httpProtocol))
}

Thanks,
Arun

Stéphane Landelle - Any suggestions ??