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

  1. Create a thread group under the test plan.

    创建线程组

  2. Add once-only controller and "MQTT Connection Sampler" (ie "MQTT Connect") under Thread Group.

    添加 MQTT 连接采样器

  3. 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

      MQTT Pub Sampler

  4. Add a "fixed timer" under MQTT Pub Sampler to control the frequency of publishing messages.

    添加固定定时器

Subscription script

  1. Add thread group under test plan.

    增加线程组

  2. Add once-only controller and "MQTT connection sampler" (ie "MQTT Connect") under thread group

    添加 MQTT 连接采样器1

  3. 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

      MQTT Sub Sampler

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:

EMQX Dashboard

appendix

Readers can download the test script to run and view the results.

Other articles in this series

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


EMQX
336 声望438 粉丝

EMQ(杭州映云科技有限公司)是一家开源物联网数据基础设施软件供应商,交付全球领先的开源 MQTT 消息服务器和流处理数据库,提供基于云原生+边缘计算技术的一站式解决方案,实现企业云边端实时数据连接、移动、...