简体   繁体   English

具有容错功能的最佳设计,用于定期调用 API 检索更新

[英]Best design with fault tolerant for retrieving updates periodically invoking an API

I am a client say clientA, I will need to call a server say serverA in a periodic manner every 15 minutes to get new updates from serverA.我是一个客户说clientA,我需要每15分钟定期调用一个服务器说serverA,以从serverA获取新的更新。

ServerA is only capable to expose an API which intakes 2 parameters - Start Time and End Time and returns list of newly created account details. ServerA 只能公开一个 API,它接受 2 个参数——开始时间和结束时间,并返回新创建的帐户详细信息列表。

Example serverA exposes: REST GET Api looks something like this示例 serverA 公开:REST GET Api 看起来像这样

http://somedomainname.com/getAccounts?startTime={say currentTime-15minutes}&endTime={say currentTime}

Response:回复:

{[
123,
456,
789
....
]} // List of account numbers that was created in serverA between supplied start time and end time.

As clientA, I will have to call above API periodically (say every 15 minutes) and store the updates in my client database.作为clientA,我将不得不定期调用上述API(比如每15分钟一次)并将更新存储在我的客户端数据库中。 What would be the best approach to design my clientA system invoking serverA API, retrieving updates and storing in my client database considering the fault tolerance like if serverA is down for any reason or clientA itself is down or any other un-expected error scenarios.设计调用 serverA API 的 clientA 系统的最佳方法是什么,检索更新并将其存储在我的客户端数据库中,考虑到容错性,例如 serverA 因任何原因关闭或 clientA 本身关闭或任何其他意外错误场景。 I wanted to as well avoid duplicate calls in the retry mechanism.我还想避免重试机制中的重复调用。

It would be great to hear your opinion on this.很高兴听到您对此的看法。 My clientA to be written in Java language with Spring Boot framework我的 clientA 将使用 Spring Boot 框架用 Java 语言编写

In my experience if it's possible to sync data between systems better to use push instead of pull approach.根据我的经验,如果可以在系统之间同步数据,最好使用推送而不是拉取方法。 Pulling updates from API especially by multiple clients can quickly lead to problems with API performance.从 API 中提取更新,尤其是由多个客户端更新会很快导致 API 性能出现问题。 Contrary push approach scale better - any number of clients can subscribe to update and publisher of updates can send them in convenient time.相反的推送方法可以更好地扩展——任何数量的客户端都可以订阅更新,更新的发布者可以在方便的时候发送它们。

But coming back to you questions.但回到你的问题。 I any case you need some sort of anchor to keep track when was last successful retrieval of updates.我无论如何都需要某种锚来跟踪上次成功检索更新的时间。 In very simple scenario - store in the DB table with one field eg LastSuccesfullAccountUpdateCallDatetime .If call succeed update this field.在非常简单的场景中 - 使用一个字段存储在数据库表中,例如LastSuccesfullAccountUpdateCallDatetime 。如果调用成功,则更新此字段。 If call fails you don't update it.如果呼叫失败,您不会更新它。 Next time you client knows where to start.下次您的客户知道从哪里开始。 In more complicated scenario in that table you can store all the time periods used to retrieve account update.在该表中更复杂的情况下,您可以存储用于检索帐户更新的所有时间段。 Eg例如

ID StartTime           Success
1  01-01-2021 00:00:00 true
2  01-01-2021 00:15:00 false
3  01-01-2021 00:30:00 true

Those time periods could be generated upfront or just inserted by client as a result of call.这些时间段可以预先生成,也可以由客户作为调用的结果插入。

Then you can link this Id to Account table and perform reconciliation for every time period if needed.然后,您可以将此 ID 链接到 Account 表,并在需要时为每个时间段执行对帐。 Let's for TimePeriod.Id = 1 you have in the DB accounts : 123,456 but later turned out that there were more.让我们在数据库帐户中设置 TimePeriod.Id = 1: 123,456 ,但后来发现还有更多。 You make a call with time stored in the DB, got eg 123,456,789 and you see that 789 should be added.您使用存储在数据库中的时间拨打电话,例如123,456,789 ,您看到应该添加 789。

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

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