简体   繁体   English

SpringBoot Rest API 带故障转移回退

[英]SpringBoot Rest API with failover fallback

I am building rest API in springboot , where my application receive list of data in a request and update the records in DB.我正在springboot中构建 rest API ,我的应用程序在请求中接收数据列表并更新数据库中的记录。 I have new requirement where i need to check if any exception thrown by DataBase like Database is down then i need to save the requested data and apply reattempt once Database is up.我有新的要求,我需要检查数据库抛出的任何异常(如数据库)是否已关闭,然后我需要保存请求的数据并在数据库启动后重新尝试。

To achieve this requirement I am using the ActiveMQ where when Database throw any exception then put the requested data in queue and once data base is UP then read the queue and insert the data again in DB.为了达到这个要求,我使用了ActiveMQ ,当数据库抛出任何异常时,将请求的数据放入queue中,一旦数据库启动,然后读取队列并再次将数据插入数据库中。

Is there any other way in springboot where i can use something else instead of using ActiveMQ ? springboot中还有其他方法可以使用其他方法而不是使用ActiveMQ吗?

Well, there are some approaches you can take on this.好吧,您可以采取一些方法来解决这个问题。 First of all, I would recommend you to take a look at spring-retry .首先,我建议您看一下spring-retry It is able to retry operations that failed due to some momentary problem.它能够重试由于某些暂时问题而失败的操作。 you can configure it with a number of retries and a delay between the retries.您可以使用重试次数和重试之间的延迟对其进行配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM