简体   繁体   English

如何在微服务架构中将默认数据播种到 Mongo db(或任何数据库)?

[英]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.

相关问题 如何使用 docker-compose 为 mongo 数据库做种? - How do I seed a mongo database using docker-compose? 我可以为Mongo DB做多主复制吗? 这个问题更需要使用Kubernetes的任何参考架构 - Can I do multi master replication for Mongo DB? Any reference architecture with Kubernetes is more expected in this question 如何创建 100 个项目并保存到 mongo db 数据库 - How do I create 100 items and save to mongo db database 如何清除mongo DB中多个集合的数据? - How do i clear data of multiple collections in mongo DB? 如何将数据同步添加到Mongo Db? - How Do I Add Data To Mongo Db Synchronously? 在mongo db中,我如何在集合中看到非常具体的数据? - In mongo db how do I see a very specific data in a collection? 如何在spring数据mongo db中进行这种聚合? - How to do this aggregation in spring data mongo db? 如何访问 Heroku 的默认 MongoDB 数据库。 我上传了 Heroku 没有任何 mongo 字符串 - How to access default MongoDB database of Heroku. I uploaded on Heroku without any mongo string Mongo-如何找到Mongo数据库数据所在的安装路径? - Mongo - how do I find the install path of where the data is for the mongo database? 在微服务架构中查询多个数据库 - Querying multiple database in a microservice architecture
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM