Trying Out Nanobus

A friend of mine recently asked me to take a look at Nanobus. I guess the first question is what is Nanobus? Allow me to pilfer that definition directly from the Nanobus Overview page. They define it as a lightweight framework for building secure and scalable software services. The next question is what does this really mean? To be honest, I have no idea! I guess we’ll find out together as I’m trying out Nanobus for the first time!

Getting Started

The first step in exploring the benefits of nanobus would be to first setup our environment. I’ve always been hesitant to just install stuff on my machine so I always try to use docker to test things out. The folks at Nanobus have provided instructions on installing from Linux so we’ll do that into a simple Ubuntu docker

docker run -it -v /Users/me/nanobus:/opt/app ubuntu /bin/bash

root@6285563b1c00:/# apt update 
Get:1 https://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:2 https://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]              
Get:3 https://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]              
Get:4 https://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [1882 kB]
...
root@6285563b1c00:/# apt -y install wget curl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
...
root@6285563b1c00:/# wget -q https://nanobus.io/install.sh -O - | /bin/bash
Your system is linux_amd64
Installing NanoBus...

Getting the latest NanoBus...

Installing v0.0.20 NanoBus...
Downloading https://github.com/nanobus/nanobus/releases/download/v0.0.20/nanobus_linux_amd64.tar.gz ...
nanobus installed into /usr/local/bin successfully.
version = 0.0.20
commit  = 5a81c91e241bc2a83895b0353d97a33f6cf0954a
date    = 2023-01-30T20:48:03Z

NanoBus is installed successfully.
root@6285563b1c00:/# 

It looks like I now have it installed. Let’s run the version switch to see if it’s there

root@6285563b1c00:/# nanobus version
version = 0.0.20
commit  = 5a81c91e241bc2a83895b0353d97a33f6cf0954a
date    = 2023-01-30T20:48:03Z

If you’d like to make your life easier, I’ve created a simple Dockerfile to get this environment up and running as well.

Shall We Try Hello World?

There’s a Github repo that contains a number of different examples that we can try out. As with anything new, it’s always a great idea to start with the Hello world example if it exists. The first step in creating our application is to first create a bus.yaml file that looks like

id: hello-world
version: 0.0.1
interfaces:
  Greeter:
    sayHello:
      steps:
        - name: Return greeting message
          # expr will evaluate a value and assign it
          # to the output of this pipeline.
          uses: expr
          with:
            # $ or pipe represent the input data
            # for this step.
            value: '"Hello, " + $.name'

From there, we execute this with our nanobus command

root@6285563b1c00:/opt/app/hello-world# echo '{"name": "World!"}' | nanobus invoke bus.yaml Greeter::sayHello
"Hello, World!"

This seems pretty straight forward where the expr outputs whatever is in value. Based upon the $.name path, this appears to use a JSON syntax path. Based upon our JSON input of {"name":"World!"}, we can see that the json name is substituted into the value string. In addition to this, the Greeter::sayHello is telling it which Interface to execute. Let’s try getting a little more fancy with it and use a nested JSON on a different Greeter entry.

id: hello-world
version: 0.0.1
interfaces:
  Greeter:
    sayHello:
      steps:
        - name: Return greeting message
          # expr will evaluate a value and assign it
          # to the output of this pipeline.
          uses: expr
          with:
            # $ or pipe represent the input data
            # for this step.
            value: '"Hello, " + $.name'
    sayNestedHello:
      steps:
        - name: Return greeting message
          # expr will evaluate a value and assign it
          # to the output of this pipeline.
          uses: expr
          with:
            # $ or pipe represent the input data
            # for this step.
            value: '"Hello, " + $.nested.name'

Let’s try running the same command as before and also our new one with the updated information

root@6285563b1c00:/opt/app/hello-world# echo '{"name": "World!"}' | nanobus invoke bus.yaml Greeter::sayHello
"Hello, World!"

root@6285563b1c00:/opt/app/hello-world# echo '{"nested":{"name": "World!"}}' | nanobus invoke bus.yaml Greeter::sayNestedHello
"Hello, World!"

Trying Out Nanobus With Docker

I have something of use up and running from the CLI but what happens if I were to try and simply deploy this in Docker? After writing this post, I noticed that the folks at Nanobus had indeed created their own Docker image, nanobus/nanobus. I decided to quickly put together a new Dockerfile that uses their image and my bus.yaml. After building this image, I tried running it to see what happened

% docker run -p 8080:8080 nanbous:hw run /opt/bus.yaml
2023-01-31T21:40:37.443Z	INFO	Initializing codec	{"name": "text/html", "type": "text/html"}
2023-01-31T21:40:37.443Z	INFO	Initializing codec	{"name": "bytes", "type": "bytes"}
2023-01-31T21:40:37.443Z	INFO	Initializing codec	{"name": "json", "type": "json"}
2023-01-31T21:40:37.443Z	INFO	Initializing codec	{"name": "msgpack", "type": "msgpack"}
2023-01-31T21:40:37.443Z	INFO	Initializing codec	{"name": "cloudevents+avro", "type": "cloudevents+avro"}
2023-01-31T21:40:37.443Z	INFO	Initializing codec	{"name": "cloudevents+json", "type": "cloudevents+json"}
2023-01-31T21:40:37.443Z	INFO	Initializing codec	{"name": "text/plain", "type": "text/plain"}
2023-01-31T21:40:37.444Z	INFO	Warning: no transports configured

I wonder what that means? It means there’s no way to interact with application from outside the container :facepalm: If you checkout the Nanobus Transports page, the very first sentence says How you application is accessed by users or triggered by events. Clearly, I have not configured a way for someone to interact with my microservice.

Conclusion

There’s me trying out nanobus and it seems pretty neat. The concept seems pretty straight forward for developing microservices. Obviously, this initial hello world example is super simple and not very useful. I did have to do some digging to understand the actions. I’ve filed a GitHub issue on their project so we’ll see what their response time is for new issues!

I’ve been meaning to build an API for something so I think the next post on Nanobus is going to focus on building an API server.