JMS
JMS protocol DSL
JMS support was initially contributed by Jason Koch.
Prerequisites
Gatling JMS DSL is not imported 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.
connectionFactory
: mandatory, an instance ofConnectionFactory
. UsejmsJndiConnectionFactory
_ to obtain one via JNDI lookup or create it by yourself.credentials
: optional, to create a JMS connectionuseNonPersistentDeliveryMode
/usePersistentDeliveryMode
: optional, default to non persistentmatchByMessageId
/matchByCorrelationId
/messageMatcher
: specify how request and response messages should be matched, default tomatchByMessageId
. UsematchByCorrelationId
for ActiveMQ.replyTimeout
: optional reply timeout, in milliseconds, default is nonelistenerThreadCount
: optional listener thread count, some JMS implementation (like IBM MQ) need more than on MessageListener to achieve full readout performance
JMS JNDI Connection Factory
Use jmsJndiConnectionFactory
object to obtain an instance of JMS ConnectionFactory
via JNDI lookup.
connectionFactoryName
: mandatoryurl
: mandatorycontextFactory
: mandatorycredentials
: optional, for performing JNDI lookupproperty
: optional, custom JNDI property
JMS Request API
Use the jms("requestName")
method in order to create a JMS request.
Request Type
Currently, requestReply
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)
, otherwise a dynamic queue will be used.
If you do so, you have to possibility of not setting the JMSReplyTo
header with noJmsReplyTo
.
Additionally for reply destination JMS selector can be defined with selector("selector")
If you have the need, to measure the time when a message arrive at a different message queue then the replyDestination(JmsDestination)
you can additional define a trackerDestination(JmsDestination)
.
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 io.gatling.core.Predef._
import io.gatling.jms.Predef._
import javax.jms._
import scala.concurrent.duration._
class TestJmsDsl extends Simulation {
// create a ConnectionFactory for ActiveMQ
// search the documentation of your JMS broker
val connectionFactory =
new org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:61616")
// alternatively, you can create a ConnectionFactory from a JNDI lookup
val jndiBasedConnectionFactory = jmsJndiConnectionFactory
.connectionFactoryName("ConnectionFactory")
.url("tcp://localhost:61616")
.credentials("user", "secret")
.contextFactory("org.apache.activemq.jndi.ActiveMQInitialContextFactory")
val jmsConfig = jms
.connectionFactory(connectionFactory)
.usePersistentDeliveryMode
val scn = scenario("JMS DSL test").repeat(1) {
exec(jms("req reply testing").requestReply
.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
}
}
}