突然对 “Event-driven programming”, “Message-driven programming”, “Reactive programming”, “Functional Reactive programming” 这些概念有些混淆,搞不清楚它们之间的关系,找到一些清晰的解释赶快记录下来。
A message is an item of data that is sent to a specific destination. An event is a signal emitted by a component upon reaching a given state. In a message-driven system addressable recipients await the arrival of messages and react to them, otherwise lying dormant. In an event-driven system notification listeners are attached to the sources of events such that they are invoked when the event is emitted. This means that an event-driven system focuses on addressable event sources while a message-driven system concentrates on addressable recipients. A message can contain an encoded event as its payload.
The Reactive Manifesto https://www.reactivemanifesto.org/glossary#Message-Driven
Reactive programming is generally event-driven, in contrast to reactive systems, which are message-driven—the distinction between event-driven and message-driven is clarified later in this article.
…
As mentioned previously, reactive programming—focusing on computation through ephemeral dataflow chains—tend to be event-driven, while reactive systems—focusing on resilience and elasticity through the communication, and coordination, of distributed systems—is message-driven (also referred to as messaging).
The main difference between a message-driven system with long-lived addressable components, and an event-driven dataflow-driven model, is that messages are inherently directed, events are not. Messages have a clear (single) destination, while events are facts for others to observe. Furthermore, messaging is preferably asynchronous, with the sending and the reception decoupled from the sender and receiver respectively.
O’REILLY https://www.oreilly.com/radar/reactive-programming-vs-reactive-systems/