tallence / push-notification-kafka-plugin

A driver for Dovecot's Push Notification Framework for publishing push notification events to a Kafka broker.
Other
6 stars 4 forks source link
dovecot email kafka kafka-producer

Kafka Driver for Dovecot's Push Notification Framework

This project provides a driver for Dovecot's Push Notification Framework for sending push notifications events to a Kafka broker. The events will be rendered as JSON data structures.

Disclaimer

This project is under active development and not in any kind of release state. Be aware it is possible and very likely that APIs, interfaces and or the data format change at any time before a first release.

The code is in a developer tested state, but is NOT production ready. Although the code is still flagged as experimental, we encourage users to try it out for non-production clusters and non-critical data sets and report their experience, findings and issues.

push-notification-kafka

The provided driver for Dovecot's Push Notification Framework is a thin wrapper around the framework events. They are rendered as JSON data structures and published to a Kafka topic. librdkafka is used for accessing the Kafka brokers as a producer.

Compile and install the Plugins

To compile the plugin you need a configured or installed Dovecot >= 2.2.21.

Checking out the source

You can clone from github with

git clone https://gitlab1.tallence.com/Telekom/push-notification-kafka-plugin.git

The build requires that you have the following software/packages installed:

librdkafka-devel version >= 0.11.4
dovecot-devel

Dovecot installation in /usr/local

./autogen.sh
./configure
make
sudo make install

Dovecot installation in ~/dovecot

./autogen.sh
./configure --prefix=/home/<user>/dovecot
make install

Configured source tree in ~/workspace/core

./autogen.sh
./configure --with-dovecot=/home/<user>/workspace/core
make install

Configuration

mail_plugins

Follow the instructions in Dovecot's Push Notification Framework description. Add the driver push_notification_kafka to the list of mail_plugins:

mail_plugins = $mail_plugins notify push_notification push_notification_kafka

Plugin Configuration

To active the Kafka driver an entry push_notification_driver has to be added to the Dovecot plugin configuration, specifying the Kafka driver URL.

push_notification_driver = kafka:topic=dovecot
push_notification_driver2 = kafka:topic=expunge events=FlagsClear,FlagsSet,MessageExpunge userdb=k1,k2

The Kafka driver is able to produce to one Cluster of Kafka brokers. You can start multiple driver instances publishing to different topics with different configurations.

The following options can be configured as part of the driver URL:

Some general communications properties are configurable in the plugin section:

Event Serialization

The events are serialized as JSON data structures. The invariant prefix for all events is

The following example illustrates an event

{
  "user": "520000004149-0001",
  "userdb": {
    "k1": "v1",
    "k2": "k2"
  },
  "mailbox": "INBOX",
  "event": "FlagsClear",
  "uidvalidity": 1531299564,
  "uid": 13,
  "flags": [
    "\\Seen"
  ]
}

A mail is identified by

Depending of the actual event type additional fields like keyword or flags are send.

{"user":"520000004149-0001","mailbox":"INBOX","event":"FlagsClear","uidvalidity":1531299564,"uid":13,"keywords":["$label2","$label1"]}
{"user":"520000004149-0001","userdb": {"k1":"v1","k2":"k2"},"mailbox":"INBOX","event":"FlagsClear","uidvalidity":1531299564,"uid":13,"flags":["\\Seen"]}
{"user":"520000004149-0001","mailbox":"INBOX","event":"FlagsSet","uidvalidity":1531299564,"uid":13,"keywords":["$label1"]}
{"user":"520000004149-0001","mailbox":"INBOX","event":"FlagsSet","uidvalidity":1531299564,"uid":13,"flags":["\\Seen"]}
{"user":"520000004149-0001","mailbox":"INBOX","event":"MessageRead","uidvalidity":1531299564,"uid":13}
{"user":"520000004149-0001","mailbox":"INBOX","event":"FlagsSet","uidvalidity":1531299564,"uid":13,"keywords":["$label2"]}
{"user":"520000004149-0001","mailbox":"INBOX","event":"FlagsClear","uidvalidity":1531299564,"uid":13,"keywords":["$label2","$label1"]}
{"user":"520000004149-0001","mailbox":"INBOX","event":"FlagsSet","uidvalidity":1531299564,"uid":13,"flags":["\\Deleted"]}
{"user":"520000004149-0001","mailbox":"INBOX","event":"MessageTrash","uidvalidity":1531299564,"uid":13}
{"user":"520000004149-0001","mailbox":"INBOX","event":"MessageExpunge","uidvalidity":1531299564,"uid":13}

Any known field has to be ignored by the consumer.

Known Bugs

Thanks

The development of this software is sponsored by Deutsche Telekom. We would like to take this opportunity to thank Deutsche Telekom.
Tallence carried out the initial development.
This plugin borrows heavily from Dovecot itself particularly for the automatic detection of dovecont-config (see m4/dovecot.m4). The lib-dict and lib-storage were also used as reference material for understanding the Dovecot dictionary and storage API.