简体   繁体   English

如何在 springboot 应用程序中管理更新

[英]How to manage updates in a springboot application

I am working on a springboot application, and I have to manage a particular use case.我正在开发一个 springboot 应用程序,我必须管理一个特定的用例。

Assume that we have a pipeline, where an an order containing an id and an amount is consumed by a kafka topic from IBM/AS400.假设我们有一个管道,其中包含一个 id 和一个数量的订单被来自 IBM/AS400 的 kafka 主题消费。

This order will be stored in a database, and used in Springboot for aggregations on an upper level of the application.此订单将存储在数据库中,并在 Springboot 中用于应用程序上层的聚合。

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Order implements Serializable {
        private string id;
        private String amount;
}

Let's assume that we have 2 orders, one with an amount of 500 and another one with an amount of 200.假设我们有 2 个订单,一个金额为 500,另一个金额为 200。

This two orders will be used to compute a final amount, so the final amount is 700.这两个订单将用于计算最终金额,因此最终金额为 700。

Let's assume, that we change the first order from 500 -> 1000.假设我们将第一个订单从 500 -> 1000 更改。

The first idea was to use getOne(id) + save to update.第一个想法是使用getOne(id) + save来更新。

So it would be:所以它会是:

String newAmount = OrderRepository.getOne(1);
orderToUpdate.setAmount(newAmount);
orderRepository.save(orderToUpdate);

Since the order is used on an upper level of the application, and that updating this order will do a computation using 10 years of history, which will take a long time, Is there any way to solve this issue?由于订单是在应用程序的上层使用的,更新这个订单会使用10年的历史计算,需要很长时间,请问有什么办法可以解决这个问题吗?

Please let me know, if you need more details !如果您需要更多详细信息,请告诉我!

Thanks in advance for your help在此先感谢您的帮助

If you want to remove the aggregation completely, and I don't know how many times in a day aggregation happens, you could do the following如果您想完全删除聚合,并且我不知道一天聚合发生多少次,您可以执行以下操作

Assumptions假设

  1. Aggregation is performed only once a day每天只执行一次聚合
  2. Aggregated value is stored in a database and is thread-safe聚合值存储在数据库中并且是线程安全的

Steps脚步

  1. Take the new amount, find the difference between the previous amount and new amount取新金额,求上一金额与新金额的差额
  2. Push the difference (as a real number) to a queue将差值(作为实数)推送到队列中
  3. Persist the new amount坚持新的金额
  4. From the queue, which has the ordered list of changed order values, apply the math on the persisted aggregated value, one by one.从具有已更改订单值的有序列表的队列中,将数学一一应用于持久聚合值。
  5. Audit the changes after each update to aggregated value.在每次更新聚合值后审核更改。

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

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