我正在开发三种微服务
查看商品用于向客户显示商品和添加服务管理员用于将商品链接到客户的商品,如果商品与客户相关联,则商品视图商品将返回该商品作为回应。客户使用Opt优惠来获取优惠。
在设计时,我意识到所有3个服务共享相同的功能,但也有自己的逻辑。
我应该在开发这些API时使用共享代码,还是每个API都必须有自己的代码库?
如果您正在使用,maven
那么您可以使用Maven模块。这基本上意味着您可以将服务代码提取到单独的模块中,并将该模块作为pom
所有3个微服务中的依赖项包含在内。
I am developing three micro-services
View offers is used to show offers to customer and Add offer used by service admins to link offer to customer and if offer is linked to customer, view offer will return that offer in response. Opt offers is used by customer to avail the offer.
While designing, I realized that all 3 services share same functionality, but also have their own logic.
Should I use shared code while developing these API or each API must have its own code base?
If you are using maven
then you can use Maven Modules. This basically means you can extract the service code into separate module and include that module as a pom
dependency in all 3 microservices.
Here's an example of how to do it using Spring
. If you are not using Spring
then you can have a look at another example here.