ShermaNiki

ShermaNiki

Hi,

In our company we are working on a contextual awareness mobile SDK, which we want to be able
integrate in other applications.
We also want to be able get “push notifications” inside our SDK (we can’t use the “native” mobile push notification solution) and use as less as possible battery resources.
Our Idea was to use MQTT protocol for that…
My Idea is to convince my bosses to use Elixir/Erlang based solution not only for the push but also as a solution for
RoR scale issues.
I saw the presentation of 2M connections with Phoenix and got really excited about it + the Elixir features and
the promised land of great performance.

I’m wondering If/how can we implement(“use”) MQTT protocol over phoenix sockets/channels or maybe it’s
just better for us to use solution such as EMQTT

Thanks you of answer.

Showing Posts 1 to 10

gausby

gausby

You could have a look at VerneMQ, which is an open source MQTT broker (also) build in Erlang, which supports web-sockets directly.

It is also possible to write plugins for VerneMQ in Elixir. Notice: This can impact the performance and stability of the broker, because the code is loaded into it. There are some examples out there: GitHub - larshesel/vmq_elixir_plugin: Example VerneMQ Elixir plugin · GitHub

I’ve wrapped one of their support libraries in Elixir: GitHub - gausby/gen_mqtt: DEPRECATED (use Tortoise instead): An Elixir behaviour that makes it possible to communicate with a MQTT server · GitHub which implements a process behaviour that can connect to-, listen-, and publish to a broker (not just a VerneMQ). It is a matter of implementing a MQTT process that listen to the topics, stick that process in the supervison tree, and use Phoenix broadcast to send messages to the correct recipients—This solution is not perfect as it doesn’t take clusters into consideration; I don’t think I would have more than one listener broadcasting to the Phoenix sockets as the same message would get posted more than once—but gen_mqtt should allow the implementor to deal with these problems (please tell me your thoughts if you go down this route).

ShermaNiki

ShermaNiki OP

First of all thank you for your replay!

If I understood you right, what you are basically saying is to use “external” broker - some more dedicated solution, such as VerneMQ or EMQTT and then some “client” to enable communication with the broker - which is totally good solution. But I must say that I’m a bit surprised that non of these
brokers still have their home made elixir SDK’s.
I was also wondering if can turn each Phoenix channel to a kind of broker with single client. (may be it’s total SCI-FI)
Anyway, thank you very much. If we will go with the VerneMQ/EMQTT I probably will try gen_mqtt and will gladly share my experience.

gausby

gausby

I think implementing a broker in Phoenix seems like a huge task. I would just go for VerneMQ because it already has the benefits as a broker in Phoenix would have; it can run as a cluster, it has very good throughput.

What do you mean by SDK? In VerneMQ’s case you can build plugins and have it run on the broker. You can do all kinds of things with the subscribe flow, publishing flow, and authentication Welcome | VerneMQ

I need to do all this kinds of things myself, so please get in contact via private message or other means of communication. If you are on IRC you can join #vernemq on Freenode. I am sure Erlio (the company behind VerneMQ) would love to hear your thoughts, and your use-case. I usually hang there trying to push them to do more stuff with Elixir :slight_smile:

ShermaNiki

ShermaNiki OP

Gausby, thanks again!

A bit out of scope, just wondering if you have also experience with EMQTT?
VerneMQ looks a bit young for me, did you used it in production?

Regarding the SDK, I meant just a convenient way to post / subscribe to broker.
Basically what you did by yourself - gen_mqtt. BTW the plugins feature of VerneMQ looks very interesting!

Would be great to do some stuff together! Just need to get the OK from the boss :slight_smile:
But I believe it would be also cool as of job task.

gausby

gausby

I have no experience with EMQTT, sorry. I picked VerneMQ because it was fairly easy to get started with, and the team is located in the same timezone as me, so they are available during the day. Also, it was fairly easy to connect to the broker from my Elixir application with :gen_emqtt (found in vmq_commons—this is what I later wrapped into gen_mqtt).

It is a young project, but I think it is fairly stable and they have some impressive load tests. Their webpage has pretty good documentation about the broker itself, and I hope that I’ve made some good documentation for the gen_mqtt Elixir wrapper.

Regardless of your choice in message broker you can still use gen_mqtt to subscribe and publish to topics; if you can’t it’s a bug and need to get fixed. I probably can’t share my code (which is in development and about to enter testing before going to production), but I can talk about my thoughts and how I go about architecture.

jak4

jak4

Sorry to highjack this thread, but I’m using (trying to use really) GenMQTT to talk to VerneMQ in my Phoenix application. I’m brand new to elixir/erlang/functional programming so this might be like a “doh” question.

I have an IoT Device which connects to VerneMQ. On the other side is the IoT handler who subscribes to the IoT queue. So now the IoT Device publishes a message which is correctly received by the IoT Handler. Depending on the Message the IoT Handler has to send something back to the IoT Device. And this is where everything breaks down. In the on_published callback in IoT Handler I have something similar to

{:ok, pid} = GenMQTT.start_link(IoTHandler, self)
mqtt_channel = "iot/#{iot_id}/#{iot_name}/command"
#Process.sleep(100)
GenMQTT.publish(pid, mqtt_channel, "command to do", 0)

This code only works, meaning the IoT Device only receives the published command, if the Process.sleep(100) is not uncommented. Now I know why this is happening. The start_link function takes some time to negotiate with VerneMQ and connect to it. What I don’t know is how I can utilize the callback function on_publish because I have no idea how to pass variables to the callback. Can this be achieved via the state variable? If so, how?

Thanks

OvermindDL1

OvermindDL1

Do you have a link to the docs about this on_publish method so we can look at it? :slight_smile:

OvermindDL1

OvermindDL1

Yes, this is precisely the use of state, state holds whatever you want. :slight_smile:

jak4

jak4

I can’t seem to figure it out. State is a process. But I can’t set values on it.

Where Next? Top

Trending in Questions Top

itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
yarrichar
I’m very new to Elixir, so sorry if this is a silly question: I am wondering what happens to the mailbox of a process when the machine i...
New
Hellowman
Hello everyone! I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++. Does anyone ...
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
saleyn
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews