Search code examples
httpasynchronoustcpjmeter

Jmeter - Asnc request


How I can simulate the async request from a JMeter.

Send Request from Jmeter --> Sent to Server --> Server give the acknowledge

Now how I can open a port or URL where the server can give me a response once he has completed his internal cycle/flow. and how I can read the response.


Solution

  • You can use JSR223 Sampler and write a simple TCP server in Groovy using ServerSocket which will be listening to the incoming data and doing whatever you need to be done with it.

    Reference implementation which prints received messages to jmeter.log file:

    def socketServer = new ServerSocket(1234)
    
    while (true) {
        socketServer.accept { socket ->
            socket.withStreams { input, output ->
                log.info("Received message: ${input.newReader().readLine()}")
            }
        }
    }
    

    And this is how it looks in action:

    enter image description here

    as you can see when I send hello message using HTTP Raw Request sampler it's getting printed to the JMeter log file, similarly you can capture your server's callback, just make sure that the server can reach the machine where JMeter is running, i.e. it has static IP address, incoming traffic to the port of your choice is not blocked by a firewall, etc.