Elixir to Vert.x in Examples

Distributed Systems Development A-Z Guide.

Dmytro Nasyrov
Pharos Production
3 min readMar 18, 2019

--

Elixir-to-Vert.x event bus bridge

Give us a message if you’re interested in Blockchain and FinTech software development or just say Hi at Pharos Production Inc.

Or follow us on Youtube to know more about Software Architecture, Distributed Systems, Blockchain, High-load Systems, Microservices, and Enterprise Design Patterns.

Pharos Production Youtube channel

Vert.x

Vert.x is an open source, reactive and polyglot software development toolkit from the developers of Eclipse. Reactive programming is a programming paradigm, associated with asynchronous streams, which respond to any changes or events. Similarly, Vert.x uses an event bus, to communicate with different parts of the application and passes events, asynchronously to handlers when they available. We call it polyglot due to its support for multiple JVM and non-JVM languages like Java, Groovy, Ruby, Python, and JavaScript.

Elixir

Elixir is a dynamic, functional language designed for building scalable and maintainable applications. Elixir leverages the Erlang VM, known for running low-latency, distributed and fault-tolerant systems, while also being successfully used in web development and the embedded software domain.

Make love, not war

OTP example

Let’s look at the example on event bus subscription from Elixir app. We defined a plain old GenServer(POGS) module. How will you supervise the server? It’s up to you.

GenServer

To start the TCP connection and to register the subscriber, you should do

Starting the TCP

Here we’re starting the server with ExVertx.start_server. This function starts DynamicSupervisor in your supervision tree. The first argument is the from reference for the gen_statem. Yes, we have gen_statem under the hood. It requires a tuple of pid and reference as an identifier. Event address — is the event address inside the event bus. Event host and event port is a host and a port of the event bus TCP bridge.

Connection settings

Next, we registering events listener on event_address and that’s pretty enough to start listening to the events channel.

Let’s write a straightforward example. We can receive new events in handle_info gen_server’s callback. In the current code, we’re going to receive 3 messages from the event bus and then we unregistering from the event bus.

Messages are arriving in handle_info callback.

That’s pretty it. Thank you for reading and happy coding!

Example of the project and the source code of the entire guideline you can find in our Github repo.

--

--

Dmytro Nasyrov
Pharos Production

We build high-load software. Pharos Production founder and CTO.