How can I use the same random number for two requests?

Hi all,

I’m trying to create a gatling test that performs a REST POST and Produce a Kafka message.

I need this to test performance of the system, and to more accurate results I need to create a post and complete the job with a kafka message.


val startOrder = 30000000



val endOrder = 40000000

def OrderId() = {
val r = ThreadLocalRandom.current().nextInt(startOrder, endOrder)

val post = {
.body(StringBody( session =>

“OrderId”: “${OrderId()}”,

val produce = {
.send(StringBody( session =>

{ |
“CheckoutOrderId”: “${OrderId()}”,

val scn1 = scenario(“OrderUpload”).exec(OrderUpload.produce,

scn1.inject(constantUsersPerSec(1) during(1 seconds)).protocols(httpProtocol, kafkaConf),


Does any one can give me a tip how can I perform this?

What is happening is each request is calculating it’s order id

Just add a first step and save the number as a Session variable. Then you can reference in other steps.