Shared queues

Use shared queues to pass values from one virtual user to another

Virtual users are isolated: each one has its own Session. Shared queues let virtual users exchange data, for example one group of virtual users producing identifiers that another group consumes.

You reference a queue by name. All the virtual users of a load generator that use the same name share the same queue.

Put values into a queue

Use put to add a value at the end of the queue. The value can be a literal, a Gatling EL string, or a function that reads the Session.

       
exec(
  sharedQueue("myQueue").put("#{value}"),
  sharedQueue("myQueue").put(1),
  sharedQueue("myQueue").put(session -> session.getString("value"))
);
exec(
  sharedQueue("myQueue").put("#{value}"),
  sharedQueue("myQueue").put(1),
  sharedQueue("myQueue").put((session: Session) => session.get<string>("value"))
);
exec(
  sharedQueue("myQueue").put("#{value}"),
  sharedQueue("myQueue").put(1),
  sharedQueue("myQueue").put { session -> session.getString("value") }
)
exec(
  sharedQueue("myQueue").put("#{value}"),
  sharedQueue("myQueue").put(1),
  sharedQueue("myQueue").put(session => session("value").as[String])
)

Take values from a queue

Use take to remove the value at the head of the queue and store it in the virtual user’s Session, under the attribute name you pass.

       
exec(sharedQueue("myQueue").take("value"));
exec(sharedQueue("myQueue").take("value"));
exec(sharedQueue("myQueue").take("value"))
exec(sharedQueue("myQueue").take("value"))

take waits until a value is available. Use timeout to limit how long a virtual user waits. Java, Kotlin and Scala accept a duration; JavaScript and TypeScript accept a number of seconds.

       
exec(sharedQueue("myQueue").take("value").timeout(Duration.ofSeconds(10)));
exec(sharedQueue("myQueue").take("value").timeout(10));
exec(sharedQueue("myQueue").take("value").timeout(Duration.ofSeconds(10)))
exec(sharedQueue("myQueue").take("value").timeout(10.seconds))

Poll values from a queue

Use poll to retrieve a value without waiting.

       
exec(sharedQueue("myQueue").poll("value"));
exec(sharedQueue("myQueue").poll("value"));
exec(sharedQueue("myQueue").poll("value"))
exec(sharedQueue("myQueue").poll("value"))

Get the size of a queue

Use size to store the current number of elements in the queue into the Session.

       
exec(sharedQueue("myQueue").size("queueSize"));
exec(sharedQueue("myQueue").size("queueSize"));
exec(sharedQueue("myQueue").size("queueSize"))
exec(sharedQueue("myQueue").size("queueSize"))

Edit this page on GitHub