brianmay

brianmay

Any recommendations on a MQTT client for Elixir?

Hello,

Is there a good mqtt client library for Elixir? Getting a bit disillusioned, none of the options seem very good.

  • GitHub - gausby/tortoise: A MQTT Client written in Elixir · GitHub - initially seemed very good. Particularly with the rewrite mqtt-5 support - which I suspect is in the mqtt-5 branch. But has numerous bugs, particularly when mqtt server goes down (pub requests can hang - hanging my application) or if trying to dynamically subscribe to topics at run-time. These errors aren’t always easy to reproduce on demand, and at one stage I was told that there were fundamental design issues. Was looking forward to the rewrite, but development has stalled, and status unclear. I don’t blame the author in anyway (I have a lot of projects in this state myself). Would consider contributing to mqtt-5 branch development if this is the best option.

  • GitHub - jacky-xbb/exmqtt: Elixir MQTT v5.0 Client · GitHub - no development for 15 months. But does support MQTT 5 - according to description at least.

  • A number of other options that look hopeful, but looks like development has also stalled.

  • Maybe I should be looking at erlang solutions? e.g. GitHub - emqx/emqtt: Erlang MQTT 5.0 Client · GitHub looks like it is actively maintained.

So wondering what the best option forward is. Examples:

  • Take over the development of the mqtt-5 branch on tortoise.
  • Take over another project.
  • Learn about MQTT-5 and start my own project from scratch?
  • Write Elixir wrapper for Erlang solution.

I tend to favor the last option right now. Unless of course somebody has already written such a wrapper.

But would appreciate any opinions,

Marked As Solved

Sebb

Sebb

I would go with emqtt.
There seems to be zero documentation on the web how to use it with Elixir.
We should change that.

Here is a starting point. (connects to test.mosquitto.org with no auth and subscribes to # so you get lots of messages)

deps (latest - 1.4.0 - seems to be out of sync with the docs in readme)

{:emqtt, github: "emqx/emqtt", tag: "v1.2.0"},

some code

defmodule MqttHowto do
  def hello do
    opts = [
      clientid: "my_client_id",
      host: 'test.mosquitto.org',
      port: 1883
    ]

    {:ok, pid} = :emqtt.start_link(opts)
    {:ok, _} = :emqtt.connect(pid)
    {:ok, _, _} = :emqtt.subscribe(pid, %{}, [{"#", []}])

    recv()
  end

  def recv() do
    receive do
      message -> IO.inspect(message)
    end

    recv()
  end
end

Also Liked

brianmay

brianmay

I think there are Two questions here, which I will answer:

  1. Why create a separate project?

I will face the same challenges regardless if I add the code directly to my project or not. Plus this way I am more likely to be able to get help, then if it it integrated into my project with numerous external dependencies. And I get to reuse the same code in my other projects.

There is at least one other open source software project I use that uses tortoise. Would be good to move these projects to something better supported. In fact based on the tortoise bug reports I see, I think there are a number of people who incorrectly feel that is the only option available. So demand might be higher then you think.

  1. Why base on project that is 2 years old?

The code structure + my changes is very similar to what I would be used anyway, and similar to what my existing code already expects (being based on tortoise).

While your code certainly looks simple, I believe it wouldn’t try to gracefully reconnect if there is a connection error. In fact a connection error will kill the process that called hello - as I discovered earlier - because the emqtt process is linked, when the connection dies, it dies, which will in turn kill the calling process. As these are long running processes, that is important for me, and where most of the complexity lies.

Yes better documentation would be very useful. e.g. Took me ages to work out how to get mqtt over TLS working with peer verification enabled.

brianmay

brianmay

Your theory makes sense. But if I don’t specify port: 8883 I get symptoms that look identical to what you observed. Which is somewhat weird and confusing.

… Oh wait, that default is only applicable for the CLI I think.

Hanspagh

Hanspagh

I have been using tortoise in production for a while now, without any major issues. The latest release fixed some of the problems we have had. Our use case is very simple, so maybe that is why we haven’t hit any of the problems you described

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement