Search code examples
javajmeterserver-sent-events

JMeter parallel requests with server-sent-events


I've got a JMeter test where I'm currently using a loop to find out if some condition is true. Rather than polling, I would like to (and can) use a request on a resource that sends out server-sent-events (SSE). The way it should work, is that the SSE thread is started and than another thread is started which does a request that ultimately will cause a specific event to be sent. If that event is received processing should continue.

Maybe more clear graphically. My current script looks something like this:

ThreadGroup
 |
 + request 1
 + request 2
 ...
 + request N
 + Transaction controller
 |  |
 |  + While controller
 |     + polling request
 |
 + request N+1

I would like something like this

ThreadGroup
 | 
 + request 1
 + request 2
 ...
 + <help needed here>
 |  |
 |  + event thread
 |  |   + request SSE
 |  |       + onEvent x: y = true
 |  + action thread
 |     + request N
 |     + While y=false wait
 + request N+1

Is this possible? If so how? If not, can I create a sampler to do this? Any pointers?

Groeten,

Friso


Solution

  • I think you will have to implement your own class.

    First, as a client of SSE, you should look at this:

    The second step is to implement a custom sampler that will extend this class:

    And use it with this GUI:

    Now for the most complex part (maybe we should create a github project to discuss this implementation and once finished contribute it to core JMeter project :-) ):

    • The SSESampler sampler can work in 2 modes :
      • Block until it receives the response from server, this way you can assert on result
      • Start a thread (better use a pool of threads or Reactor pattern) to listen from server, once it gets the response, we have to find a way for the initial thread to be able to access this and assert. We could work with a thread safe Map shared and where data would be keyed by some data passed to the SSESampler

    These are just initial ideas and need more work.