# WebSocket matching API - different order of responses

**URL:** <https://community.gatling.io/t/websocket-matching-api-different-order-of-responses/7838>\
**Category:** Gatling (Open-Source)\
**Created:** [April 12, 2023, 10:02am UTC](https://community.gatling.io/t/websocket-matching-api-different-order-of-responses/7838 "2023-04-12T10:02:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MSlaski](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@MSlaski](https://community.gatling.io/u/MSlaski)\
**Post date:** [April 12, 2023, 10:02am UTC](https://community.gatling.io/t/websocket-matching-api-different-order-of-responses/7838/1 "2023-04-12T10:02:17Z")

</div>

Hello,

Im using Websocket protocol during my simulation, and for one message I can got several responses. Only two of them are necessary for me to gather some data and the question is how can I handle such scenario when those two important responses can arrive in different order? For exmaple

**WS - Send some message**  
Server respond - non-important response  
**Server respond - important response 1**  
**Server respond - important response 2**

**WS - Send some message**  
Server respond - non-important response  
**Server respond - important response 2**  
**Server respond - important response 1**

Example of current implementation (hardcoded for specific order of responses)

```auto
.doWhile(checkForProperMessage).on(
        pause(Duration.ofMillis(50))
          .exec(sendMessage
            .await(6).on(Checks.firstResponse)
            .await(6).on(Checks.secondResponse)
          ))

```

Implementation of checks:

```auto
    ws.checkTextMessage("First Response")
      .matching(regex("\\d.+\"SOME_REGEX\".+"))
      .check(regex("SOME_REGEX").captureGroups(2).saveAs("some_session_id));

```

If response will match my regex I have to store some part of the message cuz there is provided information about the delay which I have to use before sending next message to give user some time to do some action during WebSocket connection

```auto
    ws.checkTextMessage("Second Response")
      .matching(regex("SOME_REGEX)
      .check(regex("(.+\"imageQuality\":\")(IMAGE_QUALITY_\\w+)(\".+)")
        .captureGroups(2).saveAs(IMAGE_QUALITY_REQUEST_GROUP_KEY));

```

And here if response will match my regex I have to store some part of response to validate if doWhile step is satisfied or not

Both messages can appear at different order. Is there any way to handle such case?

BR  
Mateusz

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [April 12, 2023, 1:57pm UTC](https://community.gatling.io/t/websocket-matching-api-different-order-of-responses/7838/2 "2023-04-12T13:57:29Z")

</div>

I don’t think that’s possible atm.

I think this would require:

- being able to set a check without sending a message first
- being able to buffer inbound messages to cope with messages that would be received just before setting such check

---

<div class="post-metadata">

**Author:** ![MSlaski](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@MSlaski](https://community.gatling.io/u/MSlaski)\
**Post date:** [April 13, 2023, 12:20pm UTC](https://community.gatling.io/t/websocket-matching-api-different-order-of-responses/7838/3 "2023-04-13T12:20:22Z")

</div>

so, at the moment it’s possible to write some checks with regex like .+ and store all of them in Session API. After that create custom method to parse all stored responses - which I believe will be not very convenient in context of performance

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/2X/b/b148e0742de35c6280726cabf3ecd3de2d320f63.png) [@system](https://community.gatling.io/u/system)\
**Post date:** [May 13, 2023, 12:21pm UTC](https://community.gatling.io/t/websocket-matching-api-different-order-of-responses/7838/4 "2023-05-13T12:21:17Z")

</div>

Closed on May 13, 2023, 12:21pm UTC

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