2025-05-22 22:24:51 +00:00
|
|
|
# Custom Plugins
|
|
|
|
|
2025-05-30 22:50:31 +00:00
|
|
|
With the aMQTT Broker plugins framework, one can add additional functionality to the broker without
|
|
|
|
having to subclass or rewrite any of the core broker logic. To define a custom list of plugins to be loaded,
|
|
|
|
add this section to your `pyproject.toml`"
|
|
|
|
|
|
|
|
```toml
|
|
|
|
[project.entry-points."mypackage.mymodule.plugins"]
|
|
|
|
plugin_alias = "module.submodule.file:ClassName"
|
|
|
|
```
|
|
|
|
|
|
|
|
and specify the namespace when instantiating the broker:
|
|
|
|
|
|
|
|
```python
|
|
|
|
from amqtt.broker import Broker
|
|
|
|
|
|
|
|
broker = Broker(plugin_namespace='mypackage.mymodule.plugins')
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
Each plugin has access to the full configuration file through the provided `BaseContext` and can define
|
|
|
|
its own variables to configure its behavior.
|
|
|
|
|
2025-06-01 15:03:20 +00:00
|
|
|
::: amqtt.plugins.base.BasePlugin
|
2025-05-30 22:50:31 +00:00
|
|
|
|
2025-06-13 11:11:49 +00:00
|
|
|
## Events
|
|
|
|
|
|
|
|
Plugins that are defined in the`project.entry-points` are notified of events if the subclass
|
2025-05-30 22:50:31 +00:00
|
|
|
implements one or more of these methods:
|
2025-05-22 22:24:51 +00:00
|
|
|
|
|
|
|
- `on_mqtt_packet_sent`
|
|
|
|
- `on_mqtt_packet_received`
|
|
|
|
- `on_broker_pre_start`
|
|
|
|
- `on_broker_post_start`
|
|
|
|
- `on_broker_pre_shutdown`
|
|
|
|
- `on_broker_post_shutdown`
|
|
|
|
- `on_broker_client_connected`
|
|
|
|
- `on_broker_client_disconnected`
|
|
|
|
- `on_broker_client_subscribed`
|
|
|
|
- `on_broker_client_unsubscribed`
|
|
|
|
- `on_broker_message_received`
|
|
|
|
|
|
|
|
|
|
|
|
## Authentication Plugins
|
|
|
|
|
2025-05-30 22:50:31 +00:00
|
|
|
Of the plugins listed in `project.entry-points`, one or more can be used to validate client sessions
|
2025-05-22 22:24:51 +00:00
|
|
|
by specifying their alias in `auth` > `plugins` section of the config:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
auth:
|
|
|
|
plugins:
|
|
|
|
- plugin_alias_name
|
|
|
|
```
|
|
|
|
|
2025-05-30 22:50:31 +00:00
|
|
|
These plugins should subclass from `BaseAuthPlugin` and implement the `authenticate` method.
|
2025-05-22 22:24:51 +00:00
|
|
|
|
|
|
|
::: amqtt.plugins.authentication.BaseAuthPlugin
|
|
|
|
|
|
|
|
## Topic Filter Plugins
|
|
|
|
|
2025-05-30 22:50:31 +00:00
|
|
|
Of the plugins listed in `project.entry-points`, one or more can be used to determine topic access
|
2025-05-22 22:24:51 +00:00
|
|
|
by specifying their alias in `topic-check` > `plugins` section of the config:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
topic-check:
|
2025-05-30 22:50:31 +00:00
|
|
|
enable: True
|
2025-05-22 22:24:51 +00:00
|
|
|
plugins:
|
|
|
|
- plugin_alias_name
|
|
|
|
```
|
|
|
|
|
2025-05-30 22:50:31 +00:00
|
|
|
These plugins should subclass from `BaseTopicPlugin` and implement the `topic_filtering` method.
|
2025-05-22 22:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
::: amqtt.plugins.topic_checking.BaseTopicPlugin
|