Skip to content

Commit a12ce09

Browse files
committed
Document the updated hook-based mod_event_pusher logic
Also: - Restructure the docs - Start with a simple introduction - Follow with configuration - Only then provide developer's info - Update migration guide
1 parent a04ad27 commit a12ce09

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

doc/migrations/6.4.0_6.5.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Instead of always sending all notifications, it only enables the ones with a rel
3232

3333
Make sure you have all the necessary sections present in the configuration file before upgrading.
3434

35+
### Custom backends for `mod_event_pusher`
36+
37+
If you have a custom backend implemented for `mod_event_pusher`, you need to update it to handle the `push_event` hook instead of implementing the `mod_event_pusher` behaviour (which no longer exists).
38+
3539
### Deprecation
3640

3741
MSSQL backend is deprecated and will be removed in the next release.

doc/modules/mod_event_pusher.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
## Module Description
22

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.
75
Currently supported backends include [http], [push], [rabbit] and [sns].
86
Refer to their specific documentation to learn more about their functions and configuration options.
97

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-
168
!!! Warning
179
This module does not support [dynamic domains](../configuration/general.md#generalhost_types).
1810

@@ -46,6 +38,36 @@ The `[modules.mod_event_pusher]` section itself is omitted - this is allowed in
4638
[modules.mod_event_pusher.rabbit]
4739
```
4840

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+
4971
[http]: ./mod_event_pusher_http.md
5072
[push]: ./mod_event_pusher_push.md
5173
[rabbit]: ./mod_event_pusher_rabbit.md

doc/modules/mod_event_pusher_rabbit.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ and for "received" events:
185185
}
186186
```
187187

188+
## Additional metadata
189+
190+
If you decide to [customize the events](mod_event_pusher.md#event-customization) with additional metadata, the additional key-value pairs will be added directly to the JSON object. You can override existing properties, but it is counter-intuitive and thus not recommended.
191+
188192
## Metrics
189193

190194
The module provides some metrics related to RabbitMQ connections and messages

0 commit comments

Comments
 (0)