|
1 | 1 | ## Module Description |
2 | 2 |
|
3 | | -This module is a generic interface for event-pushing backends. |
4 | | -It defines a single callback, `push_event/2` that forwards the event to all registered backends. |
5 | | -Each backend decides how and if to handle the event in its `push_event/2` implementation. |
6 | | - |
| 3 | +This module is a generic interface for pushing **events** to the configured **backends**. |
| 4 | +The events include presence updates and incoming/outgoing messages. |
7 | 5 | Currently supported backends include [http], [push], [rabbit] and [sns]. |
8 | 6 | Refer to their specific documentation to learn more about their functions and configuration options. |
9 | 7 |
|
10 | | -### How it works |
11 | | - |
12 | | -The events are standardized as records that can be found in the `mod_event_pusher_events.hrl` file. |
13 | | -Common events like user presence changes (offline and online), chat and groupchat messages (incoming |
14 | | -and outgoing) are already handled in the `mod_event_pusher_hook_translator` module, which is a proxy between various hooks and the `push_event/2` handler. |
15 | | - |
16 | 8 | !!! Warning |
17 | 9 | This module does not support [dynamic domains](../configuration/general.md#generalhost_types). |
18 | 10 |
|
@@ -46,6 +38,36 @@ The `[modules.mod_event_pusher]` section itself is omitted - this is allowed in |
46 | 38 | [modules.mod_event_pusher.rabbit] |
47 | 39 | ``` |
48 | 40 |
|
| 41 | +## How it works |
| 42 | + |
| 43 | +The events are standardized as records that can be found in the `mod_event_pusher_events.hrl` file. |
| 44 | +Common events like user presence changes (offline and online), chat and groupchat messages (incoming and outgoing) are handled in the `mod_event_pusher_hook_translator` module. |
| 45 | +Each event has a corresponding [hook](../developers-guide/Hooks-and-handlers.md), e.g. `user_send_message` is run when a user sends a message. |
| 46 | +`mod_event_pusher_hook_translator` has a handler function for each supported hook. |
| 47 | + |
| 48 | +Handling an event includes the following steps: |
| 49 | + |
| 50 | +1. The event hook is executed, and the corresponding handler function in `mod_event_pusher_hook_translator` is called. |
| 51 | +1. The handler function calls `mod_event_pusher:push_event(Acc, Event)`. |
| 52 | +1. `mod_event_pusher:push_event/2` runs another hook called `push_event`. |
| 53 | +1. All configured backend modules have handlers for the `push_event` hook, and all these handlers are called. |
| 54 | + |
| 55 | +### Custom event processing |
| 56 | + |
| 57 | +By implementing your own module handling the `push_event` hook, you can: |
| 58 | + |
| 59 | +- Push the events to a new service, such as a message queue or a database. |
| 60 | +- Filter the events by returning `{ok, ...}` to keep an event, or `{stop, ...}` to drop it. |
| 61 | +- Add a map with **metadata** to the events. The keys need to be atoms, and the values need to be atoms, binaries or numbers. |
| 62 | + |
| 63 | +There is an example [mod_event_pusher_filter.erl](https://github.com/esl/MongooseIM/blob/master/big_tests/tests/mod_event_pusher_filter.erl) module, demonstrating how to filter the events and append additional metadata. |
| 64 | + |
| 65 | +!!! Note |
| 66 | + Execution order of handlers depends on their priorities. In particular, filtering events or adding metadata needs to happend before pushing notifications to external services. The example handler has the priority value of 10, while backends have the priority of 50. |
| 67 | + |
| 68 | +!!! Warning |
| 69 | + Currently only the [rabbit](mod_event_pusher_rabbit.md#additional-metadata) backend supports adding metadata to the published notifications. |
| 70 | + |
49 | 71 | [http]: ./mod_event_pusher_http.md |
50 | 72 | [push]: ./mod_event_pusher_push.md |
51 | 73 | [rabbit]: ./mod_event_pusher_rabbit.md |
|
0 commit comments