'Access session value in gatling checks

I use gatling to send data to an ActiveMQ. The payload is generated in a separate method. The response should also be validated. However, how can I access the session data within the checks check(bodyString.is()) or simpleCheck(...)? I have also thought about storing the current payload in a separate global variable, but I don't know if this is the right approach. My code's setup looks like this at the moment:

val scn = scenario("Example ActiveMQ Scenario")
  .exec(jms("Test").requestReply
    .queue(...)
    .textMessage{ session => val message = createPayload(); session.set("payload", payload); message}
    .check(simpleCheck{message => customCheck(message, ?????? )})) //access stored payload value, alternative: check(bodystring.is(?????) 

def customCheck(m: Message, string: String) = {
 // check logic goes here
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source