我们如何在Maven项目中使用gatling-mqtt插件进行负载测试
问题描述:
我有一个java maven项目,我希望能够使用gatling测试我们的mqtt代理的性能。我明白,gatling直接不支持mqtt协议。我们如何在Maven项目中使用gatling-mqtt插件进行负载测试
我在github中遇到了gatling-mqtt plugin。我不知道如何在我的Maven项目中使用这个插件。我无法找到现有的Maven插件或依赖项。
我已经加入的pom.xml以下依赖性
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>2.2.5</version>
</dependency>
<dependency>
<groupId>io.gatling</groupId>
<artifactId>gatling-core</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.fusesource.mqtt-client</groupId>
<artifactId>mqtt-client</artifactId>
<version>1.12</version>
</dependency>
及以下插件:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>performanceTests</id>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<simulationClass>simulation.Publish</simulationClass>
</configuration>
</execution>
</executions>
</plugin>
我想写非常相似,这样的模拟:
import io.gatling.core.Predef._
import org.fusesource.mqtt.client.QoS
import scala.concurrent.duration._
import com.github.mnogu.gatling.mqtt.Predef._
class MqttSimulation extends Simulation {
val mqttConf = mqtt
// MQTT broker
.host("tcp://localhost:1883")
val scn = scenario("MQTT Test")
.exec(mqtt("request")
// topic: "foo"
// payload: "Hello"
// QoS: AT_LEAST_ONCE
// retain: false
.publish("foo", "Hello", QoS.AT_LEAST_ONCE, retain = false))
setUp(
scn
.inject(constantUsersPerSec(10) during(90 seconds)))
.protocols(mqttConf)
}
但是为了编写这样的场景,我无法使用mqtt对象。
我得到的错误是'找不到:值mqtt'
答
我创建了一个我加入我的项目中的gatling-mqtt项目的jar。那时我可以使用mqtt对象。
您可以通过下载sbt来创建jar。在您的控制台中,从项目路径运行命令'$ sbt assembly'。这会为你创建一个罐子。
请您仔细阅读并修改:https://*.com/help/how-to-ask –
您应该也可以阅读https://*.com/help/on-topic和https:// *.com/help/dont-ask – hardillb
欢迎来到Stack Overflow!请[编辑]您的问题以显示[迄今为止的代码](http://whathaveyoutried.com)。你至少应该包含一个你遇到问题的代码大纲(但最好是[mcve]),然后我们可以尝试帮助解决特定的问题。你还应该阅读[问]。 –