-
Couldn't load subscription status.
- Fork 24
Open
Copy link
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Summary
- We propose adding:
- A shared, reusable MQTT client service configured from appsettings, to be registered in the service collection and usable across multiple features.
- A Resource MQTT integration service that uses
IResourceManagementandIResourceManagementChangesto publish resource events and handle subscriptions via the shared MQTT client. - A design that allows future reuse of the same MQTT client in a similar service built on
IProductManagement.
Motivation
- Based on Add abstractions for resources synchronized throughout multiple MORYX applications #656 and Expose ResourceChanged notifications from ResourceManagement as a non-breaking facade extension #657, we want to allow applications to share resources throughout multiple MORYX instances
- One provider of the synchronization itself can be MQTT, this is what the feature request proposes
Proposed Design
-
Configuration
- Add a typed options class bound from appsettings:
- Section: Mqtt
- Properties:
- Host (string)
- Port (int)
- ClientId (string)
- Username (string, optional)
- Password (string, optional/secret)
- UseTls (bool, default false)
- CleanSession (bool, default true)
- KeepAliveSeconds (int, default 30)
- ReconnectDelaySeconds (int, default 5)
- TopicPrefix (string, default "moryx")
- QoS (int 0..2, default 1)
- Retain (bool, default false)
-
Shared MQTT client abstraction
IMqttClientService- Lifetime: Singleton, registered in DI, and also implements IHostedService for lifecycle management (connect on start, disconnect on stop).
- Uses MQTTnet client options built from
MqttOptionsto handle connection, TLS, credentials, keep-alive, and auto-reconnect logic. - Logs connection state changes and errors.
- Designed for reuse by a future ProductManagement MQTT service.
-
Resource MQTT integration service
- A BackgroundService (or IHostedService) that depends on:
IResourceManagement(from ResourceManagementFacade)IResourceManagementChanges(from ResourceManagementFacade)- IMqttBus
- IOptions
- ILogger
- Responsibilities:
- Subscribe to
IResourceManagementevents:- ResourceAdded
- ResourceRemoved
- Publish event messages to MQTT topics. Suggested topics:
- {TopicPrefix}/resources//added
- {TopicPrefix}/resources//removed
- Subscribe to
- Payload: json serialization of resource object (using System.Text.Json with Web defaults)
- respect
ISerializableinterface andIResourceSerializableinterface for resources
- respect
- Ensure ValidateHealthState is respected by only accessing facade operations in event callbacks or on Start when module is healthy.
- A BackgroundService (or IHostedService) that depends on:
-
Future extension: Product MQTT integration service
- A separate service (not part of this change set, but supported by the shared
IMqttClientService) that would: - Depend on
IProductManagement - Reuse same
IMqttClientServiceinstance and configuration.
- A separate service (not part of this change set, but supported by the shared
-
Registration
- Provide an extension method to register everything in DI, similar to
AddControllers
- Provide an extension method to register everything in DI, similar to
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request