Through the previous articles, I believe that you are already familiar with the basic knowledge of JMeter and the use of MQTT plug-ins. In this article, we will introduce the use of JMeter MQTT plugin in subscription and publishing test scenarios.
Introduction to Subscription and Publishing Scenarios
Post scene
Use MQTT Connect to request the simulated device to establish a connection with the MQTT server (this article takes EMQX as an example), then use MQTT Pub Sampler to request the simulated device to publish messages to the MQTT Broker, and add a fixed timer after the MQTT Pub Sampler to simulate regular publishing of messages.
Subscription publish scenario
Use the MQTT Connect request to simulate establishing a connection with the MQTT Broker, in which the subscriber subscribes to the specified topic and the publisher publishes messages to the specified topic.
Writing test scripts using the MQTT plugin
post script
Create a thread group under the test plan.
Add once-only controller and "MQTT Connection Sampler" (ie "MQTT Connect") under Thread Group.
Add the MQTT Pub Sampler after the MQTT connection sampler for publishing messages.
- QoS Level is the message level, supports 0, 1, 2
- Retained Mesages is whether to retain the message, support true, false
- Topic name is the topic name
- Add timestamp in payload Add timestamp to message
- Message type : String You can fill in a custom string message
- Message type : Hex string can fill in custom hexadecimal message
Message type : Randmom string with fixed length is a fixed length random character, followed by Length is the specified length
Add a "fixed timer" under MQTT Pub Sampler to control the frequency of publishing messages.
Subscription script
Add thread group under test plan.
Add once-only controller and "MQTT connection sampler" (ie "MQTT Connect") under thread group
Add MQTT Sub Sampler after MQTT Connect to simulate subscribing messages.
- QoS Level message level, support 0, 1, 2
- Topic name(s) Subscription topic name, support +/# wildcard shared subscription
- Payload includes timestamp Whether the packet includes a timestamp
- Sample on : specified elapsed time(ms) Subscribe to messages by millisecond time statistics
- Sample on : number of received messages Subscribe to messages by count
Debug response Debug return information, that is, display detailed subscription messages in the viewing result tree
execution of tests
Debug and verify the prepared script to confirm whether the connectivity of the MQTT Broker and the script running logic are as expected.
Modify the number of thread groups on the thread group page to 50, set the number of loops to 1000, and click the Start button on the page to execute the test.
To view the test results, click "View Result Tree" to view the content of publish and subscribe messages.
From the summary report, it can be seen that the throughput of Pub and Sub is 161.5/s, and the number of messages of 50 publishers and 50 subscribers is 50*1000, that is, the throughput of publish and subscribe is consistent with the number of messages.
Log in to the EMQX Dashboard page, as shown below:
appendix
Readers can download the test script to run and view the results.
Other articles in this series
- Introduction to open source testing tool JMeter - IoT large concurrency testing practice 01
- Introduction to JMeter Test Components - IoT Large Concurrency Test Practice 02
- How to use the MQTT plugin in JMeter - IoT large concurrency test practice 03
- The use of JMeter MQTT in connection test scenarios - IoT large concurrency test combat 04
Copyright statement: This article is original by EMQ, please indicate the source when reprinting.
Original link: https://www.emqx.com/zh/blog/the-use-of-jmeter-mqtt-in-subscription-and-publishing-test-scenarios
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。