Internet of Things - Reactive and Asynchronous with Vert.x

Vert.x IoT

This is a re-​publication of the fol­low­ing blog post.

I have to admit … be­fore join­ing Red Hat I didn’t know about the Eclipse Vert.x project but it took me few days to fall in love with it!

For the other de­vel­op­ers who don’t know what Vert.x is, the best de­f­i­n­i­tion is …

… a toolkit to build dis­trib­uted and re­ac­tive sys­tems on top of the JVM using an asyn­chro­nous non block­ing de­vel­op­ment model

The first big thing is re­lated to de­velop a re­ac­tive sys­tem using Vert.x which means :

  • Re­spon­sive : the sys­tem re­sponds in an ac­cept­able time;
  • Elas­tic : the sys­tem can scale up and scale down;
  • Re­silient : the sys­tem is de­signed to han­dle fail­ures grace­fully;
  • Asyn­chro­nous : the in­ter­ac­tion with the sys­tem is achieved using asyn­chro­nous mes­sages;

The other big thing is re­lated to use an asyn­chro­nous non block­ing de­vel­op­ment model which doesn’t mean to be multi-​threading but thanks to the non block­ing I/O (i.e. for han­dling net­work, file sys­tem, …) and call­backs sys­tem, it’s pos­si­ble to han­dle a huge num­bers of events per sec­ond using a sin­gle thread (aka “event loop”).

You can find a lot of ma­te­r­ial on the of­fi­cial web site in order to bet­ter un­der­stand what Vert.x is and all its main fea­tures; it’s not my ob­jec­tive to ex­plain it in this very short ar­ti­cle that is mostly … you guess … mes­sag­ing and IoT ori­ented :-)

In my opin­ion, all the above fea­tures make Vert.x a great toolkit for build­ing In­ter­net of Things ap­pli­ca­tions where being re­ac­tive and asyn­chro­nous is a “must” in order to han­dle mil­lions of con­nec­tions from de­vices and all the mes­sages in­gested from them.

Vert.x and the Internet of Things

As a toolkit, so made of dif­fer­ent com­po­nents, what are the ones pro­vided by Vert.x and use­ful to IoT?

Start­ing from the Vert.x Core com­po­nent, there is sup­port for both ver­sions of HTTP pro­to­col so 1.1 and 2.0 in order to de­velop an HTTP server which can ex­pose a REST­ful API to the de­vices. Today , a lot of web and mo­bile de­vel­op­ers pre­fer to use this pro­to­col for build­ing their IoT so­lu­tion lever­ag­ing on the deep knowl­edge they have about the HTTP pro­to­col.

Re­gard­ing more IoT ori­ented pro­to­cols, there is the Vert.x MQTT server com­po­nent which doesn’t pro­vide a full bro­ker but ex­poses an API that a de­vel­oper can use in order to han­dle in­com­ing con­nec­tions and mes­sages from re­mote MQTT clients and then build­ing the busi­ness logic on top of it, so for ex­am­ple de­vel­op­ing a real bro­ker or ex­e­cut­ing pro­to­col trans­la­tion (i.e. to/from plain TCP,to/from the Vert.x Event Bus,to/from HTTP,to/from AMQP and so on). The API raises all events re­lated to the con­nec­tion re­quest from a re­mote MQTT client and all sub­se­quent in­com­ing mes­sages; at same time, the API pro­vides the way to reply to the re­mote end­point. The de­vel­oper doesn’t need to know how MQTT works on the wire in terms of en­cod­ing/de­cod­ing mes­sages.

Re­lated to the AMQP 1.0 pro­to­col there are the Vert.x Pro­ton and the AMQP bridge com­po­nents. The first one pro­vides a thin wrap­per around the Apache Qpid Pro­ton en­gine and can be used for in­ter­act­ing with AMQP based mes­sag­ing sys­tems as clients (sender and re­ceiver) but even de­vel­op­ing a server. The last one pro­vides a bridge be­tween the pro­to­col and the Vert.x Event Bus mostly used for com­mu­ni­ca­tion be­tween de­ployed Vert.x ver­ti­cles. Thanks to this bridge, ver­ti­cles can in­ter­act with AMQP com­po­nents in a sim­ple way.

Last but not least, the Vert.x Kafka client com­po­nent which pro­vides ac­cess to Apache Kafka for send­ing and con­sum­ing mes­sages from top­ics and re­lated par­ti­tions. A lot of IoT sce­nar­ios lever­age on Apache Kafka in order to have an in­ges­tion sys­tem ca­pa­ble of han­dling mil­lion mes­sages per sec­ond.

Conclusion

The cur­rent Vert.x code base pro­vides quite in­ter­est­ing com­po­nents for de­vel­op­ing IoT so­lu­tions which are al­ready avail­able in the cur­rent 3.3.3 ver­sion (see Vert.x Pro­ton and AMQP bridge) and that will be avail­able soon in the fu­ture 3.4.0 ver­sion (see MQTT server and Kafka client). Of course, you don’t need to wait for their of­fi­cial re­lease be­cause, even if under de­vel­op­ment, you can al­ready adopt these com­po­nents and pro­vide your feed­back to the com­mu­nity.

This ecosys­tem will grow in the fu­ture and Vert.x will be a lead­ing actor in the IoT ap­pli­ca­tions world based on a mi­croser­vices ar­chi­tec­ture!

Next post

Building services and APIs with AMQP 1.0

Microservices and APIs are everywhere. Everyone talks about them, presentation slides are full of them ... some people are actually even building them.

Read more
Previous post

Getting started with new fabric8 Vert.x Maven Plugin

The all new fabric8 Vert.x Maven Plugin allows you to setup, package, run, start, stop and redeploy easily with a very little configuration resulting in a less verbose pom.xml.

Read more
Related posts

Building services and APIs with AMQP 1.0

Microservices and APIs are everywhere. Everyone talks about them, presentation slides are full of them ... some people are actually even building them.

Read more

Building a real-time web app with Angular/Ngrx and Vert.x

There are multiple tech stacks to build a real-time web app. What are the best choices to build Angular client apps, connected to a JVM-based backend?

Read more

Real-time bidding with Websockets and Vert.x

The expectations of users for interactivity with web applications have changed over the past few years. Users during bidding in auction no longer want to press the refresh button.

Read more