How to receive JSON response in JMeter web socket sampler

Issue #222 resolved
Former user created an issue

We have an API scenario where we need to establish the websocket connection and then we need to subscribe to the notification to receive the message notifications. We are able to establish the connection WebSocket sampler but couldn't read any notification post the connection is established. Tried multiple samplers(Read, Request-Response, Ping/Pong) to retrieve the notification message but we are getting response as Frame(sid: value) but not the JSON response data.

How can I get the JSON response in response body in JMeter?

Comments (6)

  1. Peter Doornbosch repo owner

    The read-sampler should do what you want, it will show the content of the web-socket message in the response field. So, if the server sends JSON in the message, this will show up in the response field. This is not different from receiving text: on web-socket protocol level JSON is just text. If you don’t see JSON, then it is likely the server did not send it (assuming you are looking at the right spot 😉).

    I don’t get what you mean with “we are getting response as Frame(sid: value)”

  2. Bhavya Meghana Puvvadi

    Thanks for the response.

    We can access the API only with VPN access.
    From Postman, after connection is established we are subscribing to an notification listener and able to see the notification response in JSON format.

    But when we are trying to simulate the same with JMeter using Web Socket Open Connection & Web Socket Single Read Sampler, we are able to establish the connection and received 2 messages as response [Frames(Sid)].

    we received response as below:

    [Frame 1]
    0{"sid":"xxxxxxxxxxxxxxxx","upgrades":[],"pingInterval":25000,"pingTimeout":20000}

    [Message 2]
    0{"sid":"xxxxxxxxxxxxxxxxx","upgrades":[],"pingInterval":25000,"pingTimeout":20000}

    but couldn’t read any messages in JSON format.

    so may I know if this scenario is possible from JMeter to read the message in JSON format?

  3. Peter Doornbosch repo owner

    Well, i tried to explain that in my first response. Yes, it is possible to received JSON messages with this plugin. In fact, you can receive any type of message, because the plugin has no knowledge of what is in the message, for the plugin it is just text. That is how the WebSocket protocol works: you can exchange text or binary messages and the protocol does not know or care what is in it. Interpretation of the message (whether it is JSON or XML or plain english or whatever) is up to the client (you in this case 😉).

    If the server sends text in JSON format, JMeter will show the JSON. It is as simple as that. JMeter/the plugin don’t do anything with the content, they just show what is received.

    Compare it with ordinary mail. You can put in an envelope everything you want, the postman does not care and your mailbox either. When you open the envelope, you can read the content the sender has sent to you. JMeter just opens the envelope and shows the content that was in. If the content is not what you expected, you should ask the sender 😉.

    Still, i don’t get what you mean with “we are getting response as Frame(sid: value)”. [Frame 1], [Message 2], this is not the kind of output that the plugin produces, so i have literally no idea what you are referring to. Why not add a screenshot to show what you get?

  4. Bhavya Meghana Puvvadi

    We have another API to push the message and this API should establish the connection and receive the message using socket.io protocol.

    We want to reproduce the same in JMeter, please help.

  5. Peter Doornbosch repo owner

    Ah, you are using socket.io, that is what causes the confusion.

    The plugin supports the websocket protocol. This is not the same as socket.io: that is a protocol layer on top of websockets. What you see in the JMeter Response is the socket.io response.

    Apparently, Postman has protocol-level support for socket.io (indeed: https://blog.postman.com/postman-now-supports-socket-io/), and hides all the socket.io layer stuff for you and only presents the JSON. That made you think that (only) JSON is send over the websocket connection, but that is not the case.

    See also https://bitbucket.org/pjtr/jmeter-websocket-samplers/src/master/FAQ.md, “Can I use the websocket plugin for Protobuf, SignalR, Stomp, ...?”

    Hth,
    Cheer
    Peter

  6. Log in to comment