diff --git a/README.md b/README.md index 99b7639..6dbec8a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ - Communication over TCP and/or websocket, including support for SSL/TLS - Support QoS 0, QoS 1 and QoS 2 messages flow - Client auto-reconnection on network lost -- Functionality expansion; plugins included: authentication and `$SYS` topic publishing +- Custom functionality expansion; plugins included: authentication, `$SYS` topic publishing, session persistence ## Installation diff --git a/amqtt/plugins/persistence.py b/amqtt/plugins/persistence.py index c24ad70..a23737a 100644 --- a/amqtt/plugins/persistence.py +++ b/amqtt/plugins/persistence.py @@ -111,6 +111,14 @@ class StoredMessage(Base): class SessionDBPlugin(BasePlugin[BrokerContext]): + """Plugin to store session information and retained topic messages in the event that the broker terminates abnormally. + + Configuration: + - file *(string)* path & filename to store the session db. default: `amqtt.db` + - clear_on_shutdown *(bool)* if the broker shutdowns down normally, don't retain any information. default: `True` + + """ + def __init__(self, context: BrokerContext) -> None: super().__init__(context) @@ -298,7 +306,6 @@ class SessionDBPlugin(BasePlugin[BrokerContext]): """Configuration variables.""" file: str | Path = "amqtt.db" - retain_interval: int = 5 clear_on_shutdown: bool = True def __post_init__(self) -> None: diff --git a/docs/packaged_plugins.md b/docs/packaged_plugins.md index bc43d3a..74a2207 100644 --- a/docs/packaged_plugins.md +++ b/docs/packaged_plugins.md @@ -47,8 +47,6 @@ By default, the `PacketLoggerPlugin` is activated and configured for the clien ```yaml plugins: - . - . amqtt.plugins.authentication.AnonymousAuthPlugin: allow_anonymous: false ``` @@ -242,3 +240,25 @@ and `on_mqtt_packet_received`. plugins: amqtt.plugins.logging_amqtt.PacketLoggerPlugin: ``` + + +### Session Persistence + +`amqtt.plugins.persistence.SessionDBPlugin` + +Plugin to store session information and retained topic messages in the event that the broker terminates abnormally. + +**Configuration** + +- `file` - *(string)* path & filename to store the session db. default: `amqtt.db` +- `clear_on_shutdown` *(bool)* if the broker shutdowns down normally, don't retain any information. default: `True` + +```yaml +plugins: + amqtt.plugins.persistence.SessionDBPlugin: + file: 'amqtt.db' + clear_on_shutdown: True +``` + + + diff --git a/docs_web/index.md b/docs_web/index.md index 8d4110d..3f933d6 100644 --- a/docs_web/index.md +++ b/docs_web/index.md @@ -10,7 +10,7 @@ - Communication over TCP and/or websocket, including support for SSL/TLS - Support QoS 0, QoS 1 and QoS 2 messages flow - Client auto-reconnection on network lost -- Functionality expansion; plugins included: authentication and `$SYS` topic publishing +- Custom functionality expansion; plugins included: authentication, `$SYS` topic publishing, session persistence ## Installation diff --git a/tests/plugins/test_persistence.py b/tests/plugins/test_persistence.py index 63d8a8c..7fab154 100644 --- a/tests/plugins/test_persistence.py +++ b/tests/plugins/test_persistence.py @@ -142,7 +142,7 @@ async def test_update_stored_session(db_file, broker_context, db_session_factory )""" await db.execute(sql) await db.commit() - + await session_db_plugin.on_broker_client_subscribed(client_id='test_client_1', topic='my/topic', qos=2) # verify that the stored session has been updated with the new subscription