简体   繁体   English

如何处理 java 中 webhook 请求的服务器停机时间

[英]how to handle server downtime for webhook requests in java

My application(A) gets file processing details from another java application(B) through rest api. App B sends the status with real-time processing details (Inprogess, Generated, Transfered).我的应用程序 (A) 通过 rest api 从另一个 java 应用程序 (B) 获取文件处理详细信息。应用程序 B 发送带有实时处理详细信息的状态(进行中、已生成、已传输)。 Application reads this info and displays it to the user.应用程序读取此信息并将其显示给用户。 when the status is Transfered.. App A performs some task.当状态为 Transferred.. App A 执行一些任务。

App A is completely dependent on App B for performing future task. App A 完全依赖于 App B 来执行未来的任务。

The Communication between two application is one-way.两个应用程序之间的通信是单向的。 App B -> App A. As of now App B perform some script for file processing and send details through rest-api.应用程序 B -> 应用程序 A。截至目前,应用程序 B 执行一些文件处理脚本并通过 rest-api 发送详细信息。 App B doesnt store this info anywhere. App B 不会将此信息存储在任何地方。

Looking for best practise to handle the request from App B during my app A downtime.寻找在我的应用程序 A 停机期间处理来自应用程序 B 的请求的最佳实践。

I found that message queue is best solution for this usecase.我发现消息队列是这个用例的最佳解决方案。 Unfortunately we cant have any new infrastructure for message queue.不幸的是,我们不能为消息队列提供任何新的基础设施。

Is there any other solution that we can implement in java without having any infra level changes.我们是否可以在 java 中实施任何其他解决方案,而无需更改任何基础设施级别。 I appreciate your time for going through this query.感谢您花时间完成此查询。 Thankyou谢谢

Assuming a DB exists in App B , you can simulate the queuing behavior.假设App B中存在一个数据库,您可以模拟排队行为。

Here is a naive implementation idea.这是一个天真的实现想法。 Let's say you have a table like the following in App B to track all the calls to be made to App A .假设您在App B中有一个如下表来跟踪对App A所有调用。

task_id任务编号 call_status通话状态 last_retry_ts最后重试时间
001 001 NOT_CALLED NOT_CALLED null null
002 002 WIP在制品 2022-12-10T10:00:01 2022-12-10T10:00:01
003 003 COMPLETE完全的 2022-12-10T10:00:01 2022-12-10T10:00:01

You can have a thread that will take all tasks that do not have a COMPLETE status and retry.你可以有一个线程来处理所有没有COMPLETE状态的任务并重试。 Once a call is successful, the thread marks them in the DB.一旦调用成功,线程就会在数据库中标记它们。 You may want to introduce some delay in between the delays.您可能想在延迟之间引入一些延迟。

Note: You may have to build some more bells and whistles to make it robust.注意:您可能需要构建更多的功能以使其健壮。

Hope this will give you some inspiration.希望这会给你一些启发。

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

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