Simple IoT Messages Delivery With GoLang — 2

Rafael Costa
2 min readFeb 12, 2022

In the previous article, we spoke about the basic IoT concepts, now we going to deep into the implementation of this concept using GoLang, you can find all of the source code in this repository. I’m going to use this repository to explain the main idea of the implementation, so in this article, I don't put a lot of code Github Gists. I considered you already have proficiency in GoLang, Docker, and Unix.

Now if we take a look at the root path in the repository we can see some configuration files: docker-compose.yml, .env, and makefile, all of these files are for configuring the project environment. Into the docker-compose file, we configure two containers, the Mosquitto MQTT Broker and the RabbitMQ. We are using the RabbitMQ for our queue provider. The .env file contains the MQTT and Queue configurations and the makefile contains some commands to help us to start our application. We going to use some external packages to help us to handle the external services:

github.com/spf13/viper;
github.com/eclipse/paho.mqtt.golang;
github.com/streadway/amqp;

The project has three main functionality:

  • Publishing data for MQTT simulating some IoT device
  • Subscribe to all of the topics in MQTT and deliver all of the messages to the RabbitMQ
  • Subscribe to the RabbitMQ Exchange/Queue to receive all of the messages.

To implement these functionalities our project has some packages, as we can see below.

|
│ └── cmd
| └── *_cmd.go
|
│ └── pkg
| ├── app
│ ├── handlers
│ └── infra

│ └── go.mod
│ └── go.sum
│ └── main.go

└───────

The CMD packages are responsible to execute our main functionalities, the PKG packages are responsible for providing the capabilities to execute the CMD packages.

To run all of the functionalities, first, you need to execute the docker-compose, running the command in your terminal:

docker-compose up

After you want to ensure you have all of the packages needed for compiling the project, to do that, running the command in your terminal:

go get -u

Now you can start the application using the makefile scripts:

make start

That is it, I hope you enjoy this short series of “Simple IoT Messages Delivery With GoLang”, feel free to send me a message to discuss this topic or anything else. Bye and be happy =^)

--

--

Rafael Costa

Backend Engineer— [GoLang] [Rust] [IoT] [IIoT] [NodeJs]