Apcera CE, The Easiest Place to Build Your First Microservice

Apcera CE, The Easiest Place to Build Your First Microservice

Are you looking to build your first microservices based application and struggling to manage how all its components will find and communicate with each other?

At Apcera we were wondering about this 5 years ago. We wanted to build a platform to run microservices, so we decided to first build our platform as a set of microservices. Makes sense right? “Do what you say and say what you do.”

We had to solve the service discovery and messaging plane puzzle ourselves first. And for that reason our CEO, Derek Collison, invented NATS, a distributed messaging system that is lightweight, high performant, and secure as the fundamental piece of the Apcera Platform. All the software components of the Apcera platform find each other and communicate with each other using NATS.

For some time NATS was just an internal component and the applications running on the Apcera Platform could not use it, but a few months ago we added the NATS service gateway, making NATS-as-a-Service a reality for all the apps running on the platform.

With the new NATS service, any app running on the platform can have its own NATS messaging system with very little configuration and without sacrificing security or reliability. In this post, I am going to show you how you can build a simple server application that broadcasts data to its clients over NATS. After that you can use can extend this example to build any kind of microservice based architecture, including things like:

  1. IoT where you read sensor data and ship it off to several clients for processing (NATS has clients for many languages, including Golang, Python, Java, Node, Elixir, C/C#, and more)
  2. Cloud Native Applications, where architectures are distributed.
  3. Microservices communication, where many application components need to communicate in real-time.

Let’s get started:

First download the Apcera Community Edition software and install it on your laptop or in any of the supported environments.

Second, download this sample application code, built to explain how NATS works.

Third, create a NATS service in the platform: apc service create mynats --type gnatsd

Apcera provides quite a few built in services, from databases to caching systems. In this case, the NATS service create and makes available a NATS Server in the platform.

Fourth, create the server side and the client side components of the application:

  1. cd server; apc app create cast-server --start
  2. cd client; apc app create cast-client --disable-routes --start

Fifth, bind the 2 microservices that just created to the NATS service:

  1. apc service bind mynats --job cast-server
  2. apc service bind mynats --job cast-client-1

And finally, you can test the microservice based application that you just created. Go back to the cast-server web page and start typing in the textbox. You should see each character sent to the logs of the client.

This process was pretty straightforward, but it can be even simpler by using the multi-job manifest feature. Once you have done the first deployment manually or you have already in the platform the packages for the 2 components of the application (the server and the client), you can simply deploy a manifest file that describe the topology of the application with a single command:

  • apc manifest deploy cast-microservice.json

Or by using the web console:

And what about if instead I am not deploying from code, but my app is already in a Docker image.  No problem, the Apcera Platform can also pull images from any docker repository, and to test it out you can use this manifest file

and run the same command:

apc manifest deploy cast-docker-microservice.json

And what about security? Apcera will only allow my microservice application to talk with cast-server. Any other connections—whether inside or outside the cluster—will be blocked.

And reliability? If the NATS service or the 2 microservices happen to crash for some reason, the Apcera Platform will automatically take care of restarting them.

For more information and more tutorials like this one see the Apcera Developer Portal.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了