{{announcement.body}}
{{announcement.title}}

Review of Microservices Frameworks: A Look at Spring Boot Alternatives

DZone 's Guide to

Review of Microservices Frameworks: A Look at Spring Boot Alternatives

Learn more about these Spring Boot alternatives for building Java and Kotlin microservices.

· Microservices Zone ·
Free Resource
Kotlin




xxxxxxxxxx
1
22


 
1
private fun createRouting(applicationInfoService: ApplicationInfoService) = Routing.builder()
2
    .register(JacksonSupport.create())
3
    .get("/application-info", Handler { req, res ->
4
        val requestTo: String? = req.queryParams()
5
            .first("request-to")
6
            .orElse(null)
7
 
           
8
        res
9
            .status(Http.ResponseStatus.create(200))
10
            .send(applicationInfoService.get(requestTo))
11
    })
12
    .get("/application-info/logo", Handler { req, res ->
13
        res.headers().contentType(MediaType.create("image", "png"))
14
        res
15
            .status(Http.ResponseStatus.create(200))
16
            .send(applicationInfoService.getLogo())
17
    })
18
    .error(Exception::class.java) { req, res, ex ->
19
        log.error("Exception:", ex)
20
        res.status(Http.Status.INTERNAL_SERVER_ERROR_500).send()
21
    }
22
    .build()


JSON




xxxxxxxxxx
1
11


 
1
webserver {
2
  port: 8081
3
}
4
 
           
5
application-info {
6
  name: "helidon-service"
7
  framework {
8
    name: "Helidon SE"
9
    release-year: 2019
10
  }
11
}


JSON




xxxxxxxxxx
1
21


 
1
ktor {
2
  deployment {
3
    host = localhost
4
    port = 8082
5
    environment = prod
6
    // for dev purpose
7
    autoreload = true
8
    watch = [io.heterogeneousmicroservices.ktorservice]
9
  }
10
  application {
11
    modules = [io.heterogeneousmicroservices.ktorservice.module.KtorServiceApplicationModuleKt.module]
12
  }
13
}
14
 
           
15
application-info {
16
  name: "ktor-service"
17
  framework {
18
    name: "Ktor"
19
    release-year: 2018
20
  }
21
}


Kotlin




xxxxxxxxxx
1
27


 
1
fun Application.module() {
2
    val applicationInfoService: ApplicationInfoService by inject()
3
 
           
4
    if (!isTest()) {
5
        val consulClient: Consul by inject()
6
        registerInConsul(applicationInfoService.get(null).name, consulClient)
7
    }
8
 
           
9
    install(DefaultHeaders)
10
    install(Compression)
11
    install(CallLogging)
12
    install(ContentNegotiation) {
13
        jackson {}
14
    }
15
 
           
16
    routing {
17
        route("application-info") {
18
            get {
19
                val requestTo: String? = call.parameters["request-to"]
20
                call.respond(applicationInfoService.get(requestTo))
21
            }
22
            static {
23
                resource("/logo", "logo.png")
24
            }
25
        }
26
    }
27
}


Kotlin




xxxxxxxxxx
1


1
fun getApplicationInfo(serviceName: String): ApplicationInfo = runBlocking {
2
    httpClient.get<ApplicationInfo>("http://$serviceName/application-info")
3
}



Kotlin




xxxxxxxxxx
1
15


 
1
@Controller(
2
    value = "/application-info",
3
    consumes = [MediaType.APPLICATION_JSON],
4
    produces = [MediaType.APPLICATION_JSON]
5
)
6
class ApplicationInfoController(
7
    private val applicationInfoService: ApplicationInfoService
8
) {
9
 
           
10
    @Get
11
    fun get(requestTo: String?): ApplicationInfo = applicationInfoService.get(requestTo)
12
 
           
13
    @Get("/logo", produces = [MediaType.IMAGE_PNG])
14
    fun getLogo(): ByteArray = applicationInfoService.getLogo()
15
}


Kotlin




xxxxxxxxxx
1
12


 
1
plugins {
2
    ...
3
    kotlin("kapt")
4
    ...
5
}
6
 
           
7
dependencies {
8
    kapt("io.micronaut:micronaut-inject-java:$micronautVersion")
9
    ...
10
    kaptTest("io.micronaut:micronaut-inject-java:$micronautVersion")
11
    ...
12
}


YAML




xxxxxxxxxx
1
16


 
1
micronaut:
2
  application:
3
    name: micronaut-service
4
  server:
5
    port: 8083
6
 
           
7
consul:
8
  client:
9
    registration:
10
      enabled: true
11
 
           
12
application-info:
13
  name: ${micronaut.application.name}
14
  framework:
15
    name: Micronaut
16
    release-year: 2018


Kotlin




xxxxxxxxxx
1


 
1
@ApplicationScoped
2
class ApplicationInfoService(
3
    ...
4
) {
5
...
6
}


Kotlin




xxxxxxxxxx
1
23


 
1
@ApplicationScoped
2
@Path("/")
3
interface ExternalServiceClient {
4
    @GET
5
    @Path("/application-info")
6
    @Produces("application/json")
7
    fun getApplicationInfo(): ApplicationInfo
8
}
9
 
           
10
@RegisterRestClient(baseUri = "http://helidon-service")
11
interface HelidonServiceClient : ExternalServiceClient
12
 
           
13
@RegisterRestClient(baseUri = "http://ktor-service")
14
interface KtorServiceClient : ExternalServiceClient
15
 
           
16
@RegisterRestClient(baseUri = "http://micronaut-service")
17
interface MicronautServiceClient : ExternalServiceClient
18
 
           
19
@RegisterRestClient(baseUri = "http://quarkus-service")
20
interface QuarkusServiceClient : ExternalServiceClient
21
 
           
22
@RegisterRestClient(baseUri = "http://spring-boot-service")
23
interface SpringBootServiceClient : ExternalServiceClient


Kotlin




xxxxxxxxxx
1


 
1
@ApplicationScoped
2
class ConsulRegistrationBean(
3
    @Inject private val consulClient: ConsulClient
4
) {
5
 
           
6
    fun onStart(@Observes event: StartupEvent) {
7
        consulClient.register()
8
    }
9
}


Kotlin




xxxxxxxxxx
1
21


1
@Provider
2
@ApplicationScoped
3
class ConsulFilter(
4
    @Inject private val consulClient: ConsulClient
5
) : ClientRequestFilter {
6
 
           
7
    override fun filter(requestContext: ClientRequestContext) {
8
        val serviceName = requestContext.uri.host
9
        val serviceInstance = consulClient.getServiceInstance(serviceName)
10
        val newUri: URI = URIBuilder(URI.create(requestContext.uri.toString()))
11
            .setHost(serviceInstance.address)
12
            .setPort(serviceInstance.port)
13
            .build()
14
 
           
15
        requestContext.uri = newUri
16
    }
17
}


YAML




xxxxxxxxxx
1
16


 
1
spring:
2
  application:
3
    name: spring-boot-service
4
 
           
5
server:
6
  port: 8085
7
 
           
8
application-info:
9
  name: ${spring.application.name}
10
  framework:
11
    name: Spring Boot
12
    release-year: 2014


  • development concept

    • On the one hand, the framework is not included in the two most popular Java development models (Spring-like (Spring Boot/Micronaut) and Java EE/MicroProfile), which can lead to:

      • a problem with finding specialists

      • an increase in the time to perform tasks compared to the Spring Boot due to the need to explicitly configure the required functionality

    • On the other hand, dissimilarity to “classic” Spring and Java EE lets look at the process of development from a different angle, perhaps more consciously

Micronaut

  • Pros

    • AOT — As previously noted, the AOT can reduce the start time and memory consumption of the application as compared to the analog on Spring Boot

    • Spring-like development model — programmers with experience with Spring framework won’t take much time to master this framework

    • Application parameters — Good results for all parameters

  • Additionally:

    • The Micronaut for Spring project allows, among other things, changing the execution environment of the existing Spring Boot application to the Micronaut (with restrictions)

Quarkus

  • Pros

    • Eclipse MicroProfile implementation. See Helidon MP

    • Application parameters — Good results for all parameters

  • Additionally:

    • The framework provides compatibility layers for several Spring technologies: DIWebSecurityData JPA

Spring Boot

  • Pros

    • Platform maturity and ecosystem — It's a framework for every day. For most everyday tasks, there is already a solution in the programming paradigm of Spring, that is, in the way that many programmers are used to. Also, development is simplified by the concept of starters and auto-configuration

    • A large number of specialists in the labor market, as well as a significant knowledge base (including documentation and answers on Stack Overflow)

    • Perspective — I think many will agree that Spring will remain the leading Java/Kotlin framework in the near future

  • Cons

    • Parameters of application — Application in this framework wasn’t among the leaders, however, some parameters, as noted earlier, you can optimize yourself. It is also worth remembering about the presence of the project Spring Fu, which is in active development and the use of which reduces these parameters

Also, we can highlight common problems that new frameworks have, but Spring Boot does not:

  • Less developed ecosystem

  • Few specialists with experience with these technologies

  • Longer time of implementation of tasks

  • Unclear prospects

The considered frameworks belong to different weight divisions: Helidon SE and Ktor are microframeworks; Spring Boot and Micronaut are full-stack frameworks; Quarkus and Helidon MP are MicroProfile frameworks. A microframework’s functionality is limited, which can slow down the development. To clarify the possibility of implementing a particular functionality based on a particular framework, I recommend that you familiarize yourself with its documentation.

I don’t dare to judge whether this or that framework will “shoot” in the near future, so in my opinion, for now, it’s best to continue to observe developments using the existing framework for solving work tasks.

At the same time, as was shown in the article, new frameworks win Spring Boot on the considered parameters of the applications. If any of these parameters are critically important for one of your microservices, then perhaps it’s worth to pay attention to the frameworks that showed the best results. However, we should not forget that Spring Boot, firstly, continues to improve, and secondly, it has a huge ecosystem and a significant number of Java programmers familiar with it. Lastly, there are other frameworks not covered in this article: Vert.x, Javalin, etc.

Thank you for reading!

P.S. Thanks to artglorin for helping with this article

Further Reading

All About Spring Boot [Tutorals and Articles]

Thoughts on Quarkus

A Quick Guide to Microservices With the Micronaut Framework

Topics:
helidon, java, kotlin, ktor, micronaut, microservices, quarkus, spring boot

Published at DZone with permission of Roman Kudryashov . See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}