Mqtt multiple device connections

I wanted to support the following scenario:

  val scn = scenario("MQTT Test").exec(
    http("Set up MQTT Connections")
  .post("hostName")
    .body(StringBody("{“name”: “do l”,“permissions”: [{“channelId”:""+channelId+"",“publish”: true, “subscribe”: true}],“description”: “test”}"))
  .exec(
    mqtt("Connecting").connect
    .cleanSession(true)
    .clientId("${clientId}")
    .credentials("${username}", "${password}")
  )
  .exec(mqtt("Subscribing").subscribe("channels/subscribe"))

Hi @reschrei,

Welcome aboard!

But what is your question? What is your issue? What are the error (if any) you see?
Help us to help you.

Note: I think your StringBody is corrupted because of the fancy quotes you use.

    .body(StringBody(s"""{"name": "do l","permissions": [{"channelId":"${channelId}","publish": true, "subscribe": true}],"description": "test"}"""))

Cheers!

yes, but that’s what not be primary interested to me, instead more of:

.exec(
    mqtt("Connecting").connect
    .cleanSession(true)
    .clientId("${clientId}")
    .credentials("${username}", "${password}")
  )

… but I see calling method issues in IntelliJ.

My Question: would it be in general possible to describe such workflow?

The only way I mean is to add protocol methos as part of:

    scn_test_ram_2.inject(constantConcurrentUsers(10).during(60.seconds))
      .protocols(mqttProtocol_2),

The idea is to feed some credentials like:

.feed("credentials.csv") 
.exec(
mqtt(“Connecting”).connect
.cleanSession(true)
.clientId(“${clientId}”)
.credentials(“${username}”, “${password}”)
)

I’ve read the following thread: MQTT gatling multiple connections to different devices

but the answers doesn’t be working!

Multiple things here.

cleanSession and credentials can’t be used with connect or subscribe and are supposed to be defined on the protocol level:

 val mqttProtocol =
  mqtt.cleanSession(true)
    .clientId("#{clientId}")
    .credentials("#{user}", "#{password}")

val scn =
  scenario("Mqtt")
    .feed(csv("credentials.csv"))
    .exec(
      mqtt("connect").connect
        .clientId("#{clientId") // won't compile
    )
    .exec(
      mqtt("sub").subscribe("topic")
    )

As stated by Stéphane in the linked post, it isn’t an issue because clientId and credentials are defined as functions at the protocol level, meaning they will be dynamically updated per client. In this case, it will read from the user attributes (filled with the credentials.csv feeder) for data.

1 Like

Ok, thx that’s working!

another interesting topic to me would be, how can read/access the response from any mqtt subscribed topic?

Feel free to open another topic, so ^^

I close this one.
Note: my purpose is letting the future visitors to easily find their already answered topic.

Cheers!