简体   繁体   English

用于在异步进程完成时进行监视的 UI 设计模式/技术

[英]UI Design pattern / technology for monitoring when an async process finishes

My frontend kicks off an async process with an http POST.我的前端使用 http POST 启动异步进程。

By whatever means, (kafka, threading, database insert and another system monitoring the table), some process is completed after an unknown amount of time and finishes in some quantifiable way (you can make a http call and determine if its done or not).通过任何方式(kafka、线程、数据库插入和另一个监控表的系统),一些过程在未知的时间后完成并以某种可量化的方式完成(你可以拨打 http 电话并确定它是否完成) .

Are there any design patterns/technologies for notifying the frontend without it having to make repeated requests to some service?是否有任何设计模式/技术可以通知前端而无需重复请求某些服务?

You can take a look on WebSockets , a bi-directional data channel that is generally used for real-time web applications.你可以看一下WebSockets ,这是一种双向数据通道,通常用于实时 web 应用程序。

The way you can use would be straight-forward: when you make the HTTP Post request and the async process is started on the backend, you also open a websocket connection with the front-end, for that particular request.您可以使用的方式是直接的:当您发出 HTTP Post 请求并在后端启动异步进程时,您还为该特定请求打开与前端的 websocket 连接。 When the async process is finished, the backend will notify the front-end through the websocket.当async进程结束后,后台会通过websocket通知前台。

You can even use the same websocket connection to transport data for multiple requests (initiated by the same user), which is a kind of a multiplexing technique.您甚至可以使用相同的 websocket 连接为多个请求(由同一用户发起)传输数据,这是一种多路复用技术。

If you need the overall system to be scalable, you should think about having a cluster of VMs that manage the websocket connections (fully separated from the backend of your application).如果您需要整个系统具有可扩展性,您应该考虑拥有一个 VM 集群来管理 websocket 个连接(与应用程序的后端完全分离)。

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

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