简体   繁体   中英

How to use different datasource of one microservice with multi instances

I'm working on a microservices architecture using Spring boot, my microservice A uses MySQL as a primary datasource I'm wondering could I make an instance of A and change datasource of that instance to MongoDB?

Why I would do that? well basically I'll have an endpoint which will handle a file uploads of million lines so I wish to have 2 datasources of that microservice.

Or should I duplicate A to another microservice B and use MongoDb as datasource and make a specific rest api?

If you use ORM (and I believe you using it) you have to create a model for both databases, because of the different concepts of MySQL and MongoDB, you have different sets of annotations. For example, for MongoDB you must use @Document instead of an @Entity. If only your service A targets this file uploads functionality - you can implement it together in one service. If you have to make uploads from multiple services or if it makes sense to have separate scaling for service A functionality and file upload feature - make it a separate service for uploads. In most cases, the second way is more attractive because it allows avoiding service duty separation in two services when you have requirements changes

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