Spring Boot and Spring Cloud choice in a Clojure micro-service

 Spring Boot and Spring Cloud

Ok, I'm back to Clojure. Then why I'm thinking about Spring framework?
I'm creating HPS as a POC to restart working in clojure and (why not) as a real service to use in production in my current company.

What we need when we deploy a new microservice in our environments is:
  1. OpenApi documentation of our service
  2. Connection to our Discovery service
  3. Interoperability with other services in an easy way, we actually have some native Spring Cloud services, and other services that register in our Discovery Server (Zookeeper) as 'fake' Spring Cloud Services. This gives us the possibility to use Feign to create Clients that are used for communications between our services.
Let's see point by point my possible solutions:

OpenApi documentation

I have 2 possibility:
  1. I write my WebService fully using Ring (I don't have any exotic requirement, I think I can do it). But this means that I will have to also write the OpenApi documentation for my API
  2. I use Spring to create my API and then I use springdoc-openapi-ui to automatically generate the OpenApi Yaml
As you can see, the second approach is really straightforward, the bad thing is that I will have to make my project a Spring Boot service, so I will have to generate Java Classes from Clojure to setup my RestController and Domain entities.

 Connection to our Discovery Service

  1. Use https://github.com/pingles/curator and register my service as 'fake' Spring Cloud service
  2. Create configuration classes for Spring Cloud
Again, the second approach is better for different reasons:
  • Widely adopted approach (Spring Cloud is used in many projects)
  • Less code to register to Zookeper, once I create configuration classes, it 'just' works

Interoperability with other services:

  1. I connect to the different services using a this rest client in clojure. 
  2. I use Feign to call other services
Unfortunately:
  1. If I go with the thin client, I will also have to call our Discovery Service, do a round robin on the different instances, do a rest call to them with the thin client or with a client created started from OpenApi for that service
  2. Feign is again configuration, and the retrieval of the service, and fallback will be handled with Hystrix, also this as the registration with Spring is widely adopted and error proof. 
My point is:

I look for a different solution: something that is adopted from the clojure community to handle this kind of environment.
So far I was not able to find a different solution, and my only possible approach is falling back on Spring for cloud and micro-service capabilities.
For tomorrow I will stop working on HPS project because:

If anyone in the clojure community, that use clojure in production, have any idea of how I can avoid this please - please - please write it in a comment :) 

Comments

  1. For OpenAPI - if you consider reitit, it supports auto generating the OpenAPI/Swagger document. There are examples of how that is done in their documentation (on github). I use reitit in production with great success.

    ReplyDelete
    Replies
    1. Thanks David, I will check it out. I'm also looking for some solutions for the service discovery :), do you have any experience with it?

      Delete
    2. Hi,

      You're welcome. I've had great success using reitit to expose a RESTful API and at the same time produce OpenAPI documentation automatically. In terms of persistance, I use next.jdbc and HoneySQL for SQL CRUD operations, (with HikariCP as my connection pool and FlywayDB for migrations) and celtuce for Redis integration. In terms of configuration it's a combination of Aero and JUXT Clip. I don't do service discovery (as all my integrations are via docker services, with known URLs, and are automatically loadbalanced) - however, if i was to do it, it would be a simple matter of using etcd or consul and using any one of the number of Clojure libraries that wrap these services. Hope that helps!

      Delete
    3. Great, thanks a lot. I will do a Poc of your stack also.
      I would love to start using clojure in my current job. I have to create the service about properties (HPS) in different ways and then I will choose what I can use in production that best suit our technology stack.

      Delete

Post a Comment