Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Building Microservices With[out] Spring Boot

DZone's Guide to

Building Microservices With[out] Spring Boot

Spring Boot has made building microservices almost effortless, but you can use other tools to achieve the same result. Read on to learn how.

· Microservices Zone ·
Free Resource

Containerized Microservices require new monitoring. See why a new APM approach is needed to even see containerized applications.

Microservices...microservices everywhere.

Everyone is talking about microservices and tools and framework to build them. One common name you may have heard of is Spring Boot. It has made creating microservices so quick and easy that even a novice developer can build one in few minutes. 

Apart from development and monitoring, a microservice consists of the following phases:

  • Packaging
  • Deployment
  • Launcher

Let's first discuss all these in details with regards to Spring Boot.

Spring Boot

Spring Boot provides out-of-the-box support for all these phases, with dedicated components in the form of plugins and modules. 

Packaging - It provides its own Maven support to package the code and all dependencies as an Uber jar, including the container itself. For this, you need to add the following build plugin and a simple repackage goal that repackages the binary built during the normal Maven package phase.

Deployment - It comes with a different type of web container to support the embedded deployment of web resources like servlets/JSP. On top of that, it provides a Jersey container that can deploy RESTful resources.

Launcher - Spring Boot has made launching an application as easy as running the Hello World program. Only one line of code triggers the dependency management, package scan, and container initialization.

Reference Code: microservice-starter-springboot

After looking into all these aspects, these artefacts could be made using different tools and frameworks. Let discuss eachweb server and platform. 

Tomcat

Tomcat is generally used as web container for deploying web applications, but it can also be used as an embedded container for running packaged microservices. For this, it requires the things below to make a contained microservice.

Packaging - Unlike Spring Boot, it does not provide an out-of-the-box solution for packaging your microservice, but you can use a Maven standard plugin like assemble and shade to build an Uber jar that contains all the dependencies and supports main class manifests.

Deployment - All the Tomcat runtime modules can be provided with a single dependency that can deploy and run the Jersey container.

Launcher - Tomcat allows you to configure your endpoint and container programmatically, and you can start and stop the instance within your control.

Reference Code: microservice-starter-tomcat

Jetty

Jetty is a perfect fit for deploying and running microservices as it mostly uses an embedded container for running web applications. It also follows the same pattern as Tomcat to run microservices.

Packaging - It can utilize Maven standard plugins to package your code and dependencies in a single Uber jar.

Deployment - Jetty provide a servlet container that can be topped up by a Jersey container to serve web services.

Launcher - Like Tomcat, it provides a similar programmatic API to deploy Jersey containers and REST endpoints.

Reference Code: microservice-starter-jetty

Grizzly

Grizzly is a less popular web container, but it powers the most standard application server for the JEE community. Yes, it's the engine behind the Glassfish server. It does provide out-of-the-box features for building microservices.

Packaging - We can use a Maven standard plugin like assembly and shade for packaging the web service and its dependencies.

Deployment - Unlike Tomcat and Jetty, it provides built-in support for deploying web services built using Jersey and provides standard container-based Grizzly HTTP services.

Launcher - Like Spring Boot, it provides a very abstract API for configuring REST services and running the container itself within a single line of code.

Reference Code: microservice-starter-grizzly

Netty

Netty is a well-known async and event-driven client/server framework that supports the majority of protocols like FTP, SMTP, and HTTP and provides low-level programming for UDP and TCP applications. On top of that, Glassfish provides a special Jersey container that uses non-blocking IO and HTTP services. It can be used as a web service container in a similar fashion to Grizzly.

Packaging - We can use a Maven standard plugin like assembly and shade for packaging the web service and its dependencies.

Deployment - Like Grizzly, it provides out-of-the-box support for deploying web services built using Jersey and provides a standard container based on Netty HTTP services.

Launcher - Like Grizzly, it provides a very abstract API for configuring REST services and running the container.

Reference Code: microservice-starter-netty

Undertow

Undertow is a web server that powers the popular JBoss AS and is able to run as an embedded container. It provides granular HTTP and non-blocking IO services. On top of that, it provides Servlet and Web Socket implementations. It can be used for building microservices in a similar fashion.

Packaging - We can use a Maven standard plugin like assembly and shade for packaging the web service and its dependencies.

Deployment - Undertow provides an HTTP Servlet container that can be used with a Jersey Servlet container.

Launcher - It also provides a programmatic API to deploy the Jersey container and REST endpoints.

Reference Code: microservice-starter-undertow

Conclusion

Now we have seen that Spring Boot is good for microservices, but you can build one with basic tool and frameworks. Also starting up is not too difficult as shown in these starter code references.

Automatically manage containers and microservices with better control and performance using Instana APM. Try it for yourself today.

Topics:
tomcat ,jetty ,grizzly ,netty ,undertow ,microservices ,spring boot ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}