java 使用 Spring Boot 和 Angular 的提醒推送通知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49672752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 10:25:33  来源:igfitidea点击:

Reminder push notification using Spring Boot and Angular

javaangularwebsocketreal-time

提问by Samir Joglekar

I need to build a web application using Spring Boot for the RESTful API and Angular (4 or 5) which will remind the user at the right time. For e.g. if I have a meeting at 11 AM, my server component should know that there is this meeting at 11 AM real-time and then push the notification through WebSockets. I could not find any useful resources on the web which can help me understand and design this specific component which needs to listen for a database event every second.

我需要使用 Spring Boot 为 RESTful API 和 Angular(4 或 5)构建一个 Web 应用程序,它会在正确的时间提醒用户。例如,如果我在上午 11 点有一个会议,我的服务器组件应该实时知道上午 11 点有这个会议,然后通过 WebSockets 推送通知。我在网络上找不到任何有用的资源可以帮助我理解和设计这个需要每秒侦听数据库事件的特定组件。

Can anyone please help me out here in architecting this single component with the right choice of tools? Should this be a queue like Apache Kafka or Apache Storm, or something else entirely?

任何人都可以在这里帮助我使用正确选择的工具构建这个单个组件吗?这应该是像 Apache Kafka 或 Apache Storm 这样的队列,还是其他的东西?

采纳答案by Bartosz Bilicki

This is web application, so events will be delivered only if user is logged in, right? In that case it is likely that most events would not be delivered because there is no user.

这是 Web 应用程序,因此只有在用户登录时才会传递事件,对吗?在这种情况下,由于没有用户,大多数事件可能不会被传递。

I would deliver events using Websocket see Spring guide how to do that https://spring.io/guides/gs/messaging-stomp-websocket/

我会使用 Websocket 传递事件,请参阅 Spring 指南如何做到这一点 https://spring.io/guides/gs/messaging-stomp-websocket/

Simple solution would schedule all events using tool like http://www.quartz-scheduler.org/. Then if event fires and user is logged in then event notification will be send using websocket. But that may be wasteful if you have large number of users.

简单的解决方案是使用像http://www.quartz-scheduler.org/这样的工具来安排所有事件。然后,如果事件触发并且用户已登录,则将使用 websocket 发送事件通知。但是,如果您有大量用户,那可能会很浪费。

More lightweight solution would be

更轻量级的解决方案是

  • when user logs in, check if he has scheduled events. Then register notifications for them at client side, using client-side javascript scheduling.
  • when there is server-side change for event for user, you need to deliver updates about those events to logged in users.
  • 当用户登录时,检查他是否安排了事件。然后在客户端为他们注册通知,使用客户端 javascript 调度。
  • 当用户的事件在服务器端发生更改时,您需要向登录用户提供有关这些事件的更新。

For me message queues doe not apply there. When you queue message for future event there is no sensible way for this message to be consumed when the event is about to occur.

对我来说消息队列在那里不适用。当您为未来事件排队消息时,没有明智的方式在事件即将发生时使用此消息。