In the Internet enterprise technology architecture ,MQ It's getting more and more important . system decoupling 、 asynchronous communication 、 Peak shaving and valley filling 、 Data order guarantee and so on , You can see... Everywhere MQ The figure of .
And the test engineer at work , And often need to talk to mq Dealing with , For example, constructing test data , Trigger some business scenarios , And aiming at mq Performance test, etc .
At present, it is well-known in the industry mq The products are kafka、rabbitmq、rocketmq etc. . Today I'm going to talk about how to use Jmeter Come to rocketmq Send a message , Realize to mq Performance test of sending message function .
Let's start with a brief introduction Rocketmq
RocketMQ It's a distributed 、 Message middleware of queue model , It is a professional message middleware independently developed by Alibaba group , After many times of tmall double 11 massive news test . It has been donated to Apache The foundation , And in 2016 year 11 Month be Apache Incubation projects .
1、MQ Basic concepts
Message: news , The carrier of information transmission in message queue
Topic: Message topic , First level message type , adopt Topic Categorize messages
Tag: Message tags , Secondary message type , Used to further differentiate a Topic Next message classification
Producer: Message producer , Also known as the publisher of the message , Responsible for producing and sending messages
Consumer： Message consumer , Also known as a message subscriber , Responsible for receiving and consuming messages
2、RocketMQ Of 4 A component
Namely nameserver、broker、producer and consumer
Broker: The core module of cluster , Mainly responsible for Topic Message store 、 Consumer's consumption point management （ Consumption progress ）Producer: Message producer , Every producer has one ID( Number )
nameserver: Store all of the current cluster Brokers Information 、Topic Follow Broker Correspondence of
Consumer: Message consumer , Each subscriber also has one ID( Number )
3、MQ Messaging model
After understanding the above concepts , Let's write Jmeter Script .
stay idea Create a Java engineering , And introduce Rocketmq and Jmeter The dependency package of , Let's write one demo Script .Rocketmq The message sending code is very simple , Just a few lines of code , The code is as follows ：
Run script , You can see the printed results “SEND_OK” word , Indicates that the message was sent successfully .
Log in to rocketmq Console page , You can search for the message you just sent .
up to now , The test script has been debugged , Just convert the script to Jmeter The script can be . It can be divided into the following steps ：
1、 Create a test class , Realization Jmeter Of JavaSamplerClient Interface , Need to implement... In the interface 4 A way , Respectively ：
setupTest： Script initialization operation , Each thread executes when it starts , And only once
runTest：Jmeter Thread loop execution method
teardownTest：Jmeter The ending method , Execute at the end of each thread , And only once
getDefaultParameters： Need to be exposed to Jmeter Parameters in the interface , For the time being, we do not need
According to the characteristics of the four methods , The corresponding mq Code operations in different ways , Detailed explanation can be seen in the comment code as follows ：
2、 take Java Scripts and their dependent packages are exported as jar package , Then put jmeter Of lib/ext Under the table of contents
3、 open Jmeter, newly build “Java request ”, Select the script class you just wrote
That's it , One is based on Jmeter Sending of MQ The message script is done , If you want to do a pressure test , stay Jmeter Configure the number of threads and duration to start the pressure measurement .