简体   繁体   中英

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 ). Resources are just endpoints.

A maintains a collection(let's call this X ) to store all the resources from different microservices. 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.

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.

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. You can algo configure the call to and endpoint with it's remote configuration feature.

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