[英]How do I seed default data to Mongo db (or any database) in a microservice architecture?
I have a use case where there are multiple microservices and one of them deals with roles and resources(let's call this microservice as A ).我有一个用例,其中有多个微服务,其中一个处理角色和资源(我们将此微服务称为A )。 Resources are just endpoints.资源只是端点。
A maintains a collection(let's call this X ) to store all the resources from different microservices. A维护一个集合(我们称之为X )来存储来自不同微服务的所有资源。 For each microservice other than A , I would like to store all of its resources(endpoints) into X the first time this microservice boots up.对于除A之外的每个微服务,我想在该微服务第一次启动时将其所有资源(端点)存储到X 中。
I am thinking of having a json file with all the resources in each microservice and calling A 's endpoint to add resources whenever a microservice boots up.我正在考虑拥有一个包含每个微服务中所有资源的 json 文件,并在微服务启动时调用A的端点来添加资源。
Is there any idiomatic way to do this?有没有什么惯用的方法来做到这一点?
Consider the use of Viper so you can set default data from multiple different sources like yaml, json, remote config like etcd, live watch of files among others.考虑使用Viper,这样您就可以设置来自多个不同来源(如 yaml、json、远程配置(如 etcd)、文件实时监视等)的默认数据。 You can algo configure the call to and endpoint with it's remote configuration feature.您可以使用它的远程配置功能来配置对和端点的调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.