NATS is a lightweight messaging protocol perfect for your IoT/Robotics projects. It operates over TCP, offers a great number of features but an incredibly simple Pub Sub style model of communicating broadcast messages. NATS is blazingly fast as it is written in Go.

This repository contains the Gobot adaptor/drivers to connect to NATS servers. It uses the NATS Go Client available at The NATS project is maintained by and sponsored by Apcera. Find more information on setting up a NATS server and its capability at

The NATS messaging protocol ( is really easy to work with and can be practiced by setting up a NATS server using Go or Docker. For information on setting up a server using the source code, visit For information on the Docker image up on Docker Hub, see Getting the server set up is very easy. The server itself is Golang, can be built for different architectures and installs in a small footprint. This is an excellent way to get communications going between your IoT and Robotics projects.

API Reference

How to Install

Install running:

go get -d -u && go install

How to Use

Before running the example, make sure you have an NATS server running somewhere you can connect to

package main

import (


func main() {
  natsAdaptor := nats.NewNatsAdaptor("nats", "localhost:4222", 1234)

  work := func() {
    natsAdaptor.On("hello", func(data []byte) {
    natsAdaptor.On("hola", func(data []byte) {
    data := []byte("o")
    gobot.Every(1*time.Second, func() {
      natsAdaptor.Publish("hello", data)
    gobot.Every(5*time.Second, func() {
      natsAdaptor.Publish("hola", data)

  robot := gobot.NewRobot("natsBot",


Supported Features

  • Publish messages
  • Respond to incoming message events
  • Support for Username/password authentication

Upcoming Features

  • Encoded messages (JSON)
  • Exposing more NATS Features (tls)
  • Simplified tests


For our contribution guidelines, please go to


Copyright (c) 2013-2017 The Hybrid Group. Licensed under the Apache 2.0 license.


Available drivers for NATS are listed below.