Getting Started With NATS

High performance messaging system and project of the CNCF

A gentle introduction

NATS, https://nats.io, is a high performance messaging system for cloud native applications, IoT device messaging, and microservices architecture.

It has been there for quite some time, as we can see from its GitHub repository where version 0.5.1 has been released in Jun 2014. It was the first release implemented in Go as NATS has its origins in Ruby with a first release in october 2010 !

NATS gained more visibility in the last few years as a CNCF’s projects. It’s currently in the Incubating stage among other very promising projects as we can see in the list below.

CNCF’s incubating projects

NATS is about publishing and subscribing to messages. A message is published on a subject, a string containing tokens separated by a dot (‘.’), which defines a kind of communication channel. A subscriber listening for incoming messages on a given subject will receive each message published on that subject.

Special chars can be used so subscribers can listen for incoming messages on a set of subjects at the same time as illustrated in the following schema.

source: https://nats.io

‘*’ wildcard for a given token

‘>’ allows to listen to all the subjects down a hierarchy

Running NATS server

In the examples of the next part we will run the NATS server from the Go release. Once we have downloaded Go the server can be started with the following commands:

$ go get github.com/nats-io/nats-server

$ nats-server

A Docker image is also available and can be run with the following command (the Alpine declination is usually a good choice as its small size limits the attack surface)