AMQP Rabbit load test

Hi there,

I am still new to Gatling and scala and have just gone through various documentation and looks like a very fascinating tool and trying my hard to get this working.
What I am trying to do is to publish a lot of messages to RabbitMQ for load testing. However the message I publish has an id in it which need to be unique for each message published.
So I have a message Template in which the delivery id will be replaced fr each message published.
So I tried using the feeder route which never worked, so thought of using session function like below.

So my scenario looks like below

val messageTemplate: String = Source.fromFile(“src/test/resources/data/Delivery.json”).getLines.mkString // This is where I get the messageTemplate from a file to a string

//Rabbit connection
implicit val amqpProtocol: AmqpProtocol = amqp.host(RMQ_HOST)
.port(5672) //.vhost("/")
.auth(“guest”, “guest”)
.poolSize(10)

val publishDelivery = scenario(“Publish Delivery”).forever (
pace(1 seconds)
.exec( // My idea here is to uniquely generate an id for the session and replace that in the template in tis exec block and store it in session

session => {
var message:String = messageTemplate.replace("${deliveryId}", Random.nextInt(10000000).toString)
session.set(“message”, message)
session
}
).exec(amqp(“Publish”).publish(PublishRequest(queue, session(“message”).as[String]))) // This exec is to actually publish the message to RabbitMQ by fetching the session value for "message"
)

However the second exec block doesn’t recognise the session(“message”)
Can you anyone suggest me where I am going wrong? Or any better solutions please? Excuse me as I am still learning and very new to this exciting tool.

Cheers

In your second exec block, you are not using a lambda expression to get direct access to the session variable (and in fact don’t need to). A minimal change would be to change that line to:

.exec(amqp(“Publish”).publish(PublishRequest(queue, “${message}”)))

There is a better solution though, which is to set “deliveryId” in the session and pass the template string direct to your publish line. Also it is worth noting that gatling runs a separate thread for each simulated user, so you should use ThreadLocalRandom:

val publishDelivery = scenario(“Publish Delivery”).forever (
pace(1 seconds)
.exec( // Randomly pick a deliveryId

session => {
session.set(“deliveryId”, ThreadLocalRandom.nextInt(10000000).toString)
session
}
).exec(amqp(“Publish”).publish(PublishRequest(queue, messageTemplate))) // This will automatically replace ${deliveryId} and any other placeholders in the template

)

If you need to be sure that no deliveryIds are repeated, you might look for a solution involving feeders with an incrementing value.

Bill

I don’t believe this works. When I test this out, the body of the message just ends up being ${message}.