简体   繁体   中英

AWS rds - How to read from a read replica inside of a Java application?

I am new to aws.

I have a mysql rds instance and I just created 2 read replicas. My application is written in Java, and what I have done up until now is using the JDBC I have connected to the one aws instance, but now how do I distribute the work around the 3 servers?

You can set up an internal Elastic Load Balancer to round robin requests to the slaves. Then configure two connections in your code: one that points directly to the master for writes and one that points to the ELB endpoint for reads.

Or if you're adventurous, you could set up your own internal load balancer using Nginx, HAProxy, or something similar. In either case, your LB will listen on port 3306.

AWS 建议设置路由 53。这是关于该主题的官方文章https://aws.amazon.com/premiumsupport/knowledge-center/requests-rds-read-replicas/

In case you have the option to use Spring boot and spring-cloud-aws-jdbc You can take a look at this working example and explanation in this post

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