简体   繁体   中英

User Interface(UI) as a different microservice in springboot

I have multiple micro services, each for particular task/activity. I am using UREKA and also gateway service.

So my question is should i have different UI microservice which will handle UI activities of all microservices? Or should i have UI part handle by respective microservice?

Yes, answer of this question is business need.

My need is i should have different UI microservice. So again below architectural issue arise, please help to resolve it.

UI Microservice : User make request for HTML, request bind to appropriate object say Employee POJO. I will handle all UI validation in that pojo and other custom validation in controller.
After successful validation, i making feign API call to Employee Microservice for saving employee object.

Employee Microservice : This microservice will contain only RestController because no UI activity over here. Above call received by appropriate controller and bind Employee object into Employee object of Employee Microservice. Then this employee object pass to service layer and converted to appropriate JPA and saved into database.

See here my Employee class get duplicated in UI microservice and Employee Microservices. Here is my question, How we can eliminate duplication of Employee class? As my UI microservice handle UI part of all other microservices, then all my POJO of microservices will duplicate in UI service which overhead modification task and duplication. One solution is to bind Employee Object of UI microservie, to directly JPA Pojo of another service directly but i don't want to expose JPA POJO before service layer. or This is good approach?

Is there is solution for this? Any design pattern?

UI microservice or service or application, whatever it is but issue of duplicate POJO is my concern

If this is the only concern that you have, yes that's the curse of microservices, code duplication.

You have creative ways to solve this problem

  1. by publishing jar(s) with all the shared POJOs

OR

  1. have all the codebase in a monorepo and build as separate jar (congratulations, eventhough your apps will be microservices you have a monolithic codebase now).

IMHO, don't just hung up on there. What if your Microservice A is written in a JVM language and microservice B is written in go. You cannot share any typed classes (AKA POJOs) there.

BTW, I wouldnt have a UI microservice. I would rather have a Single Page app (such as Angular/ React/ Vue / Yet-another-javascript-framework)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM