与多个spring应用程序共享数据

时间:2022-03-31 20:33:09

I have 1 main spring boot application and 2 dependent spring boot applications. Dependent app load some data(settings, and so on) from main app on start. Some external service may change this data in main app and dependent app should reload this data. Is there some library or framework.

我有1个主弹簧启动应用程序和2个相关的弹簧启动应用程序。从属应用程序在启动时从主应用程序加载一些数据(设置等)。某些外部服务可能会在主应用程序中更改此数据,并且相关应用程序应重新加载此数据是否有一些库或框架。

1 个解决方案

#1


0  

There are 3 solutions:

有3种解决方案:

  1. Always retrieve data from every requests. I don't think this is your case since you have loaded them on the beginning to avoid this solution.
  2. 始终从每个请求中检索数据。我不认为这是你的情况,因为你已经开始加载它们以避免这个解决方案。

  3. Refresh the initial data after some amount of time (cron job).
  4. 在一段时间(cron作业)之后刷新初始数据。

  5. Main application acts as micro-service orchestrators and inform all its dependant application that their cache may be invalid. Every dependant application answer this request by refreshing their cache.
  6. 主应用程序充当微服务协调器,并通知其所有相关应用程序其缓存可能无效。每个相关应用程序通过刷新其缓存来回答此请求。

For solution number 2 take a look at spring boot @Scheduled annotation. For example you can refresh the data every 5 minutes @Scheduled(fixedRate = 300000).

对于解决方案2,请查看spring boot @Scheduled注释。例如,您可以每5分钟刷新一次数据@Scheduled(fixedRate = 300000)。

#1


0  

There are 3 solutions:

有3种解决方案:

  1. Always retrieve data from every requests. I don't think this is your case since you have loaded them on the beginning to avoid this solution.
  2. 始终从每个请求中检索数据。我不认为这是你的情况,因为你已经开始加载它们以避免这个解决方案。

  3. Refresh the initial data after some amount of time (cron job).
  4. 在一段时间(cron作业)之后刷新初始数据。

  5. Main application acts as micro-service orchestrators and inform all its dependant application that their cache may be invalid. Every dependant application answer this request by refreshing their cache.
  6. 主应用程序充当微服务协调器,并通知其所有相关应用程序其缓存可能无效。每个相关应用程序通过刷新其缓存来回答此请求。

For solution number 2 take a look at spring boot @Scheduled annotation. For example you can refresh the data every 5 minutes @Scheduled(fixedRate = 300000).

对于解决方案2,请查看spring boot @Scheduled注释。例如,您可以每5分钟刷新一次数据@Scheduled(fixedRate = 300000)。