STOMP over a WebSocket client in Elixir

submited by
Style Pass
2021-06-10 12:00:07

For a recent project, I had the need of communicating with an external server over WebSocket using the STOMP protocol. After searching and failing to find any libraries in Elixir that could do this, I was contemplating falling back to Python’s and using ErlPort to communicate with the process. While this would definitely have been an acceptable solution, it would also be an overly complex solution, especially since STOMP is a very easy protocol and there are already some libraries in Elixir that can parse and create STOMP messages.

As it turns out it was really easy to roll out my own WebSocket client implementation that communicated using STOMP. Each STOMP message has a simple structure like this:

The header and the body could be anything depending on the interaction between the server and the client. And there are only a few client commands that STOMP supports:

With that, while it is definitely possible to parse and create messages on your own, I suggest using an existing tested library that already does this out of the box. I used Elephant, but you could use any other library or even roll out your own implementation.

Leave a Comment