Websocket handling several messages from server

Hi everyone.
the problem i face is the following.
GIVEN i open a web-socket connection
WHEN the conection is just opened
THEN i receive 4 different messages at once(with some miliseconds interval)

i want to read all messages, but whatever i do, only the first message is being read.

Hi @AlbertG,

Welcome aboard!

It seems that you will need to wait for Gatling 3.11 to be able to use the new ws.processUnmatchedMessages action.

Sample of future usage:

exec(
  // store the unmatched messages in the Session
  ws.processUnmatchedMessages((messages, session) -> session.set("messages", messages))
);
exec(
  // collect the last text message and store it in the Session
  ws.processUnmatchedMessages(
    (messages, session) -> {
      Collections.reverse(messages);
      String lastTextMessage =
        messages.stream()
          .filter(m -> m instanceof io.gatling.http.action.ws.WsInboundMessage.Text)
          .map(m -> ((io.gatling.http.action.ws.WsInboundMessage.Text) m).message())
          .findFirst()
          .orElse(null);
          if (lastTextMessage != null) {
            return session.set("lastTextMessage", lastTextMessage);
          } else {
            return session;
          }
      })
);

Source

Cheers!

@sbrevet Thanks for fast response.
Just to double-check and be on the same page I will describe the issue one more time and wait for confirmation.
In the screenshot you see 4 messages received at the same time as soon as the websocket is connected:

what try to do, is to fetch some data from the second message, or third or fourth one.
But whatever I do, I am able to reach only the first message and that’s all.
A small piece of code where I try to receive the second message but its failing.
So you suggest waiting for 3.11 in order to handle it?
Thanks again

    .exec(ws("Open Connection").connect(url)
      .onConnected(
        exec(ws("Receive First Message1")
          .sendText("")
          .await(2) {
            ws.checkTextMessage("First Message1").check(jsonPath("$").saveAs("firstMessage"))
          })
          .exec(ws("Receive Second Message")
            .sendText("")
            .await(0) {
              ws.checkTextMessage("Second Message").check(jsonPath("$").saveAs("secondMessage"))
            })

      )
    )

@AlbertG,

Indeed, it is the way I think this new action will work: as your messages arrive at connection, you may want to pause a short amount of time before processing all messages in the meantime, so you will be able to manipulate them as your wish.

Yes, because I don’t see a satisfying workaround for now.

Cheers!

If you know that you’ll be expected exactly 4 messages and the order is predefined, this is already something you can achieve with Gatling 3.10.
Please check the documentation: Gatling WebSocket protocol reference

exec(ws("Open Connection").connect(url)
  .await(2) {
      ws.checkTextMessage("First Message1").check(jsonPath("$").saveAs("firstMessage")),
      ws.checkTextMessage("Second Message").check(jsonPath("$").saveAs("secondMessage"))
  }
)

@sbrevet @slandelle
Thanks for all responses, i was not able to resolve the issue.
From the screenshot, you can see that all messages are being received almost at the same time, and I guess that’s why I can interact only with the first one.
I think while the code is being executed all other messages are already being received.
in short- I can catch only the first message, and the one that is empty (that comes with mode delay)
Is there a timeline when 3.11 version will be available, I think this is the only way to resolve my issue.


I think this is the only way to resolve my issue.

No. What I suggested should definitely work. At this point, there’s no way to help you unless you provide a reproducer we can run on our side.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.