njh / ruby-mqtt

Pure Ruby gem that implements the MQTT protocol, a lightweight protocol for publish/subscribe messaging.
http://www.rubydoc.info/gems/mqtt
MIT License
542 stars 135 forks source link

Is using a connection Pool Recommended? #157

Open coderhs opened 1 year ago

coderhs commented 1 year ago

Sorry this is not an issue but a question. If I am wrong to do it here my apologies, kindly point me in the right direction.

I am working with a ruby on rails application, that communicates using MQTT to manage devices. When ever we want to send a message we are pretty much using the below code.

    MQTT::Client.connect(host: ENV['MOSQUITTO_HOST'],
                         port: 1883,
                         username: ENV['MOSQUITTO_USERNAME'],
                         password: ENV['MOSQUITTO_PASSWORD']) do |c|
      c.publish(channel, msg)
    end

So they are connection and then pretty much finishing it, after its done.

I recently started upgrading our app to Rails 6, and found that redis gem recommends using connection pool rather than having a single connection or multiple connection.

Is that recommended for MQTT connections as well? Has anyone done this? and if so how was your experience.