-
Notifications
You must be signed in to change notification settings - Fork 0
/
jms.html
224 lines (201 loc) · 15.4 KB
/
jms.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<ol class="breadcrumb">
<li><a href="index.html">Gatling documentation</a></li>
<li><a href="">
JMS
</a></li>
</ol>
<div class="content-left-wrap col-md-9">
<div id="primary" class="content-area">
<main itemscope="" itemtype="http://schema.org/WebPageElement" itemprop="mainContentOfPage" id="main"
class="site-main">
<article id="documentation" class="type-post status-publish format-standard hentry category-non-classe">
<header class="entry-header">
<h1 class="entry-title" itemprop="headline">JMS</h1>
</header>
<div class="entry-content" itemprop="text">
<div class="section" id="jms">
<span id="id1"></span>
<p>JMS support was initially contributed by <a class="reference external" href="https://github.com/jasonk000">Jason Koch</a>.</p>
<div class="section" id="prerequisites">
<h2>Prerequisites<a class="headerlink" href="#prerequisites" title="Permalink to this headline">¶</a></h2>
<p>Gatling JMS DSL is not available by default.</p>
<p>One has to manually add the following imports:</p>
<div class="highlight-scala"><div class="highlight"><pre><span></span><span class="k">import</span> <span class="nn">io.gatling.jms.Predef._</span>
<span class="k">import</span> <span class="nn">javax.jms._</span>
</pre></div>
</div>
</div>
<div class="section" id="jms-protocol">
<h2>JMS Protocol<a class="headerlink" href="#jms-protocol" title="Permalink to this headline">¶</a></h2>
<p id="id2">Use the <code class="docutils literal"><span class="pre">jms</span></code> object in order to create a JMS protocol.</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">connectionFactory</span></code>: mandatory, an instance of <cite>ConnectionFactory</cite>. Use <a class="reference internal" href="#jmsjndiconnectionfactory">jmsJndiConnectionFactory</a> to obtain one via JNDI lookup or create it by yourself.</li>
<li><code class="docutils literal"><span class="pre">credentials</span></code>: optional, to create a JMS connection</li>
<li><code class="docutils literal"><span class="pre">useNonPersistentDeliveryMode</span></code> / <code class="docutils literal"><span class="pre">usePersistentDeliveryMode</span></code>: optional, default to non persistent</li>
<li><code class="docutils literal"><span class="pre">matchByMessageID</span></code> / <code class="docutils literal"><span class="pre">matchByCorrelationID</span></code> / <code class="docutils literal"><span class="pre">messageMatcher</span></code>: specify how request and response messages should be matched, default to matchByMessageID. Use matchByCorrelationID for ActiveMQ.</li>
<li><code class="docutils literal"><span class="pre">replyTimeout</span></code>: optional reply timeout, in milliseconds, default is none</li>
</ul>
</div>
<div class="section" id="jms-jndi-connection-factory">
<h2>JMS JNDI Connection Factory<a class="headerlink" href="#jms-jndi-connection-factory" title="Permalink to this headline">¶</a></h2>
<p>Use <cite>jmsJndiConnectionFactory</cite> object to obtain an instance of JMS <cite>ConnectionFactory</cite> via JNDI lookup.</p>
<ul class="simple" id="jmsjndiconnectionfactory">
<li><code class="docutils literal"><span class="pre">connectionFactoryName</span></code>: mandatory</li>
<li><code class="docutils literal"><span class="pre">url</span></code>: mandatory</li>
<li><code class="docutils literal"><span class="pre">contextFactory</span></code>: mandatory</li>
<li><code class="docutils literal"><span class="pre">credentials</span></code>: optional, for performing JNDI lookup</li>
<li><code class="docutils literal"><span class="pre">property</span></code>: optional, custom JNDI property</li>
</ul>
</div>
<div class="section" id="jms-request-api">
<h2>JMS Request API<a class="headerlink" href="#jms-request-api" title="Permalink to this headline">¶</a></h2>
<p id="jms-request">Use the <code class="docutils literal"><span class="pre">jms("requestName")</span></code> method in order to create a JMS request.</p>
<div class="section" id="request-type">
<h3>Request Type<a class="headerlink" href="#request-type" title="Permalink to this headline">¶</a></h3>
<p>Currently, <code class="docutils literal"><span class="pre">requestReply</span></code> and <code class="docutils literal"><span class="pre">send</span></code> (fire and forget) requests are supported.</p>
</div>
<div class="section" id="destination">
<h3>Destination<a class="headerlink" href="#destination" title="Permalink to this headline">¶</a></h3>
<p>Define the target destination with <code class="docutils literal"><span class="pre">queue("queueName")</span></code> or alternatively with <code class="docutils literal"><span class="pre">destination(JmsDestination)</span></code></p>
<p>Optionally define reply destination with <code class="docutils literal"><span class="pre">replyQueue("responseQueue")</span></code> or <code class="docutils literal"><span class="pre">replyDestination(JmsDestination)</span></code> if not defined dynamic queue will be used.</p>
<p>Additionally for reply destination JMS selector can be defined with <code class="docutils literal"><span class="pre">selector("selector")</span></code></p>
</div>
<div class="section" id="message-matching">
<h3>Message Matching<a class="headerlink" href="#message-matching" title="Permalink to this headline">¶</a></h3>
<p>Request/Reply messages are matched using JMS pattern (request JMSMessageID should be return in response as JMSCorrelationID).</p>
<p>If different logic is required, it can be specified using <code class="docutils literal"><span class="pre">messageMatcher(JmsMessageMatcher)</span></code>.</p>
</div>
<div class="section" id="message">
<h3>Message<a class="headerlink" href="#message" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">textMessage(Expression[String])</span></code></li>
<li><code class="docutils literal"><span class="pre">bytesMessage(Expression[Array[Byte]])</span></code></li>
<li><code class="docutils literal"><span class="pre">mapMessage(Expression[Map[String,</span> <span class="pre">Any]])</span></code></li>
<li><code class="docutils literal"><span class="pre">objectMessage(Expression[java.io.Serializable])</span></code></li>
</ul>
</div>
<div class="section" id="properties">
<h3>Properties<a class="headerlink" href="#properties" title="Permalink to this headline">¶</a></h3>
<p>One can send additional properties with <code class="docutils literal"><span class="pre">property(Expression[String],</span> <span class="pre">Expression[Any])</span></code>.</p>
</div>
<div class="section" id="jms-type">
<h3>JMS Type<a class="headerlink" href="#jms-type" title="Permalink to this headline">¶</a></h3>
<p>Jms type can be specified with <code class="docutils literal"><span class="pre">jmsType(Expression[String])</span></code>.</p>
</div>
</div>
<div class="section" id="jms-check-api">
<h2>JMS Check API<a class="headerlink" href="#jms-check-api" title="Permalink to this headline">¶</a></h2>
<p id="jms-api">JMS checks are very basic for now.</p>
<p>There is <code class="docutils literal"><span class="pre">simpleCheck</span></code> that accepts just <code class="docutils literal"><span class="pre">javax.jms.Message</span> <span class="pre">=></span> <span class="pre">Boolean</span></code> functions.</p>
<p>There is also <code class="docutils literal"><span class="pre">xpath</span></code> check for <code class="docutils literal"><span class="pre">javax.jms.TextMessage</span></code> that carries XML content.</p>
<p>Additionally you can define your custom check that implements <code class="docutils literal"><span class="pre">Check[javax.jms.Message]</span></code></p>
</div>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<p>Short example, assuming FFMQ on localhost, using a reqreply query, to the queue named “jmstestq”:</p>
<div class="highlight-scala"><div class="highlight"><pre><span></span><span class="k">import</span> <span class="nn">net.timewalker.ffmq3.FFMQConstants</span>
<span class="k">import</span> <span class="nn">io.gatling.core.Predef._</span>
<span class="k">import</span> <span class="nn">io.gatling.jms.Predef._</span>
<span class="k">import</span> <span class="nn">javax.jms._</span>
<span class="k">import</span> <span class="nn">scala.concurrent.duration._</span>
<span class="k">class</span> <span class="nc">TestJmsDsl</span> <span class="k">extends</span> <span class="nc">Simulation</span> <span class="o">{</span>
<span class="k">val</span> <span class="n">connectionFactory</span> <span class="k">=</span> <span class="n">jmsJndiConnectionFactory</span>
<span class="o">.</span><span class="n">connectionFactoryName</span><span class="o">(</span><span class="nc">FFMQConstants</span><span class="o">.</span><span class="nc">JNDI_CONNECTION_FACTORY_NAME</span><span class="o">)</span>
<span class="o">.</span><span class="n">url</span><span class="o">(</span><span class="s">"tcp://localhost:10002"</span><span class="o">)</span>
<span class="o">.</span><span class="n">credentials</span><span class="o">(</span><span class="s">"user"</span><span class="o">,</span> <span class="s">"secret"</span><span class="o">)</span>
<span class="o">.</span><span class="n">contextFactory</span><span class="o">(</span><span class="nc">FFMQConstants</span><span class="o">.</span><span class="nc">JNDI_CONTEXT_FACTORY</span><span class="o">)</span>
<span class="k">val</span> <span class="n">jmsConfig</span> <span class="k">=</span> <span class="n">jms</span>
<span class="o">.</span><span class="n">connectionFactory</span><span class="o">(</span><span class="n">connectionFactory</span><span class="o">)</span>
<span class="o">.</span><span class="n">usePersistentDeliveryMode</span>
<span class="k">val</span> <span class="n">scn</span> <span class="k">=</span> <span class="n">scenario</span><span class="o">(</span><span class="s">"JMS DSL test"</span><span class="o">).</span><span class="n">repeat</span><span class="o">(</span><span class="mi">1</span><span class="o">)</span> <span class="o">{</span>
<span class="n">exec</span><span class="o">(</span><span class="n">jms</span><span class="o">(</span><span class="s">"req reply testing"</span><span class="o">).</span><span class="n">requestReply</span>
<span class="o">.</span><span class="n">queue</span><span class="o">(</span><span class="s">"jmstestq"</span><span class="o">)</span>
<span class="o">.</span><span class="n">textMessage</span><span class="o">(</span><span class="s">"hello from gatling jms dsl"</span><span class="o">)</span>
<span class="o">.</span><span class="n">property</span><span class="o">(</span><span class="s">"test_header"</span><span class="o">,</span> <span class="s">"test_value"</span><span class="o">)</span>
<span class="o">.</span><span class="n">jmsType</span><span class="o">(</span><span class="s">"test_jms_type"</span><span class="o">)</span>
<span class="o">.</span><span class="n">check</span><span class="o">(</span><span class="n">simpleCheck</span><span class="o">(</span><span class="n">checkBodyTextCorrect</span><span class="o">))</span>
<span class="o">)</span>
<span class="o">}</span>
<span class="n">setUp</span><span class="o">(</span><span class="n">scn</span><span class="o">.</span><span class="n">inject</span><span class="o">(</span><span class="n">rampUsersPerSec</span><span class="o">(</span><span class="mi">10</span><span class="o">)</span> <span class="n">to</span> <span class="mi">1000</span> <span class="n">during</span> <span class="o">(</span><span class="mi">2</span> <span class="n">minutes</span><span class="o">)))</span>
<span class="o">.</span><span class="n">protocols</span><span class="o">(</span><span class="n">jmsConfig</span><span class="o">)</span>
<span class="k">def</span> <span class="n">checkBodyTextCorrect</span><span class="o">(</span><span class="n">m</span><span class="k">:</span> <span class="kt">Message</span><span class="o">)</span> <span class="k">=</span> <span class="o">{</span>
<span class="c1">// this assumes that the service just does an "uppercase" transform on the text</span>
<span class="n">m</span> <span class="k">match</span> <span class="o">{</span>
<span class="k">case</span> <span class="n">tm</span><span class="k">:</span> <span class="kt">TextMessage</span> <span class="o">=></span> <span class="n">tm</span><span class="o">.</span><span class="n">getText</span> <span class="o">==</span> <span class="s">"HELLO FROM GATLING JMS DSL"</span>
<span class="k">case</span> <span class="k">_</span> <span class="k">=></span> <span class="kc">false</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</div>
</div>
</div>
</article>
</main>
</div>
</div>
<div class="sidebar-wrap col-md-3 content-left-wrap">
<div id="secondary" class="widget-area" role="complementary" itemscope="itemscope"
itemtype="http://schema.org/WPSideBar">
<aside id="search-2" class="widget widget_search">
<form role="form" method="get" class="search-form" action="search.html">
<label>
<span class="screen-reader-text">Search through the documentation :</span>
<input type="search" class="search-field" placeholder="Search the documentation" name="q">
</label>
<input type="submit" class="search-submit" value="Search">
</form>
</aside>
<aside class="widget">
<h1 class="widget-title">Table of Content</h1>
<ul>
<li><a class="reference internal" href="#">JMS</a><ul>
<li><a class="reference internal" href="#prerequisites">Prerequisites</a></li>
<li><a class="reference internal" href="#jms-protocol">JMS Protocol</a></li>
<li><a class="reference internal" href="#jms-jndi-connection-factory">JMS JNDI Connection Factory</a></li>
<li><a class="reference internal" href="#jms-request-api">JMS Request API</a><ul>
<li><a class="reference internal" href="#request-type">Request Type</a></li>
<li><a class="reference internal" href="#destination">Destination</a></li>
<li><a class="reference internal" href="#message-matching">Message Matching</a></li>
<li><a class="reference internal" href="#message">Message</a></li>
<li><a class="reference internal" href="#properties">Properties</a></li>
<li><a class="reference internal" href="#jms-type">JMS Type</a></li>
</ul>
</li>
<li><a class="reference internal" href="#jms-check-api">JMS Check API</a></li>
<li><a class="reference internal" href="#example">Example</a></li>
</ul>
</li>
</ul>
</aside>
<aside class="widget">
<h1 class="widget-title">Previous topic</h1>
<ul>
<li>
<a href="http/sse.html" title="Previous Chapter: SSE (Server Sent Event)">
SSE (Server Sent Event)
</a>
</li>
</ul>
</aside>
<aside class="widget">
<h1 class="widget-title">Next topic</h1>
<ul>
<li>
<a href="realtime_monitoring/index.html" title="Next Chapter: Realtime monitoring">
Realtime monitoring
</a>
</li>
</ul>
</aside>
<aside class="widget">
<h1 class="widget-title">Contribute</h1>
<ul>
<li>
<a href="https://github.com/gatling/gatling/edit/master/src/sphinx/jms.rst">Edit this page on Github</a>
</li>
</ul>
</aside>
</div>
</div>