JMS

JMS support was initially contributed by Jason Koch.

Prerequisites

Gatling JMS DSL is not available by default.

One has to manually add the following imports:

import io.gatling.jms.Predef._
import javax.jms._

JMS Protocol

Use the jms object in order to create a JMS protocol.

  • connectionFactoryName: mandatory
  • url: mandatory
  • contextFactory: mandatory
  • credentials: optional, for performing JNDI lookup
  • disableAnonymousConnect: optional, by default, connection won’t use the above credentials
  • listenerCount: the number of ReplyConsumers. mandatory (> 0)
  • useNonPersistentDeliveryMode / usePersistentDeliveryMode: optional, default to non persistent
  • matchByMessageID / matchByCorrelationID / messageMatcher: specify how request and response messages should be matched, default to matchByMessageID. Use matchByCorrelationID for ActiveMQ.
  • receiveTimeout: optional receive timeout for JMS receive method, default is 0 - infinite

JMS Request API

Use the jms("requestName") method in order to create a JMS request.

Request Type

Currently, reqreply and send (fire and forget) requests are supported.

Destination

Define the target destination with queue("queueName") or alternatively with destination(JmsDestination)

Optionally define reply destination with replyQueue("responseQueue") or replyDestination(JmsDestination) if not defined dynamic queue will be used.

Additionally for reply destination JMS selector can be defined with selector("selector")

Message Matching

Request/Reply messages are matched using JMS pattern (request JMSMessageID should be return in response as JMSCorrelationID).

If different logic is required, it can be specified using messageMatcher(JmsMessageMatcher).

Message

  • textMessage(Expression[String])
  • bytesMessage(Expression[Array[Byte]])
  • mapMessage(Expression[Map[String, Any]])
  • objectMessage(Expression[java.io.Serializable])

Properties

One can send additional properties with property(Expression[String], Expression[Any]).

JMS Type

Jms type can be specified with jmsType(Expression[String]).

JMS Check API

JMS checks are very basic for now.

There is simpleCheck that accepts just javax.jms.Message => Boolean functions.

There is also xpath check for javax.jms.TextMessage that carries XML content.

Additionally you can define your custom check that implements Check[javax.jms.Message]

Example

Short example, assuming FFMQ on localhost, using a reqreply query, to the queue named “jmstestq”:

import net.timewalker.ffmq3.FFMQConstants
import io.gatling.core.Predef._
import io.gatling.jms.Predef._
import javax.jms._
import scala.concurrent.duration._

class TestJmsDsl extends Simulation {

  val jmsConfig = jms
    .connectionFactoryName(FFMQConstants.JNDI_CONNECTION_FACTORY_NAME)
    .url("tcp://localhost:10002")
    .credentials("user", "secret")
    .contextFactory(FFMQConstants.JNDI_CONTEXT_FACTORY)
    .listenerCount(1)
    .usePersistentDeliveryMode

  val scn = scenario("JMS DSL test").repeat(1) {
    exec(jms("req reply testing").reqreply
      .queue("jmstestq")
      .textMessage("hello from gatling jms dsl")
      .property("test_header", "test_value")
      .jmsType("test_jms_type")
      .check(simpleCheck(checkBodyTextCorrect))
    )
  }

  setUp(scn.inject(rampUsersPerSec(10) to 1000 during (2 minutes)))
    .protocols(jmsConfig)

  def checkBodyTextCorrect(m: Message) = {
    // this assumes that the service just does an "uppercase" transform on the text
    m match {
      case tm: TextMessage => tm.getText == "HELLO FROM GATLING JMS DSL"
      case _ => false
    }
  }
}