-
Notifications
You must be signed in to change notification settings - Fork 24
Add shared MQTT client and ResourceManagement-based MQTT integration service #720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: pre-release
Are you sure you want to change the base?
Conversation
…-breaking facade extension
- A shared, reusable MQTT client service configured from `Config/Moryx.Communication.Mqtt.Config.json`, to be registered in the service collection and usable across multiple features. - A Resource MQTT integration service that uses IResourceManagement and IResourceManagementChanges to publish resource events and handle subscriptions via the shared MQTT client.
f464e81 to
ec77e39
Compare
fb89f17 to
57473b2
Compare
src/Moryx.Communication.Mqtt.Endpoints/Moryx.Communication.Mqtt.Endpoints.csproj
Show resolved
Hide resolved
16a0c5d to
f19cfeb
Compare
3655a46 to
5b357ad
Compare
5b357ad to
0ee40da
Compare
500a558 to
32b8e49
Compare
0ee40da to
afe5c4c
Compare
src/Moryx.Communication.Mqtt/AttributeRouting/IMqttRouteTable.cs
Outdated
Show resolved
Hide resolved
| ```csharp | ||
| /// <summary> | ||
| /// Specifies the synchronization behavior for a resource's digital twin | ||
| /// across multiple application instances. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Class, Inherited = false)] | ||
| public class ResourceSynchronizationAttribute : Attribute | ||
| { | ||
| /// <summary> | ||
| /// Defines the property serialization strategy for this resource. | ||
| /// </summary> | ||
| public SynchronizationMode Mode { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Defines the property serialization strategy. | ||
| /// </summary> | ||
| public enum SynchronizationMode | ||
| { | ||
| /// <summary> | ||
| /// The entire resource object, including all its properties, is serialized and synchronized. | ||
| /// </summary> | ||
| Full, | ||
|
|
||
| /// <summary> | ||
| /// Only properties explicitly marked with the [SynchronizableMember] attribute will be | ||
| /// serialized and synchronized. | ||
| /// </summary> | ||
| Selective | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want it is better to reference the file as a link or use a markdown table with value and description. Dont copy code in docs...
| ```csharp | ||
| /// <summary> | ||
| /// Marks a property as included in the payload when its class | ||
| /// is using 'Selective' synchronization mode. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Property)] | ||
| public class SynchronizableMemberAttribute : Attribute { } | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.. why do you copy the code to the docs?
| You can also configure the Mqtt client using a configuration file just like any `MORYX` module. | ||
| ```cs | ||
| builder.Services.AddMqttClient("Moryx.Mqtt.Config"); // specify your config file name without extension | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why must the filename be defined? The config manager normally does that automatically by the typename. Which class is used for the serialization?
|
|
||
| The core of this feature is an attribute to mark an `IResource` class for synchronization. Its `Mode` property dictates which properties are included in the synchronization payload. | ||
|
|
||
| ```csharp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sometimes you use csharp, sometimes cs - i vote for constistant usage of cs.
| /// <summary> | ||
| /// Specifies the synchronization behavior for a resource's digital twin | ||
| /// across multiple application instances. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Class, Inherited = false)] | ||
| public class ResourceSynchronizationAttribute : Attribute | ||
| { | ||
| /// <summary> | ||
| /// Defines the property serialization strategy for this resource. | ||
| /// </summary> | ||
| public SynchronizationMode Mode { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Defines the property serialization strategy. | ||
| /// </summary> | ||
| public enum SynchronizationMode | ||
| { | ||
| /// <summary> | ||
| /// The entire resource object, including all its properties, is serialized and synchronized. | ||
| /// </summary> | ||
| Full, | ||
|
|
||
| /// <summary> | ||
| /// Only properties explicitly marked with the [SynchronizableMember] attribute will be | ||
| /// serialized and synchronized. | ||
| /// </summary> | ||
| Selective | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again copied code to docs..
| using Moryx.Serialization; | ||
| using MQTTnet; | ||
|
|
||
| namespace Moryx.Communication.Mqtt.Endpoints; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a special case.. this Endpoint has a dependency to mqtt stuff, and I definitely don't want a reference to that in Moryx.AbstractionLayer.Resources.Endpoints. For my POV, this endpoint should be separated because I also dont see a reference of Moryx.AbstractionLayer in Moryx.Communication.Mqtt
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Moryx.AbstractionLayer\Moryx.AbstractionLayer.csproj" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moryx.Communication.Mqtt should not reference Moryx.AbstractionLayer nor Moryx.Runtime
| <ProjectReference Include="..\Moryx.Runtime\Moryx.Runtime.csproj" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Include="README.md" Pack="true" PackagePath="" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the readme placed within the package and not part of the documentation?
| #### Route constraint | ||
|
|
||
| The available constraints are: | ||
|
|
||
| - {name: int} | ||
| - {name: int?} | ||
| - {name: string} | ||
| - {name: string?} | ||
| - {name: decimal} | ||
| - {name: decimal?} | ||
| - {name: bool} | ||
| - {name: bool?} | ||
| - {name: datetime} | ||
| - {name: datetime?} | ||
| - {name: double} | ||
| - {name: double?} | ||
| - {name: float} | ||
| - {name: float?} | ||
| - {name: guid} | ||
| - {name: guid?} | ||
| - {name: long} | ||
| - {name: long?} | ||
| - {name?} | ||
| - {name/*} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do they come from? Maybe reference another doc instead of copy the stuff into these docs.
The following Issue is resolved in this PR.
Motivation :
Based on #656 and #657, we want to allow applications to share resources throughout multiple MORYX instances.
This PR contains the following features:
IManagedMqttClientResourceSynchronizationService(Listen to resource change event and sends a message to the broker)IManagedMqttClientMqttEndpointServicefor topic template support ex: "my-topic/{id:int}/invoke/{methodName}"ResourceEventService(listen to public Resource events and sends a message to the broker)ResourceRpcEndpoint(when the client receives a method invocation message, the method is invoked on the matching resource , any return value (exceptTask<T>) is sent back to the broker)How the new feature works ?
Mqtt Service
Config/Moryx.Mqtt.Config.json{ "Host": "localhost", "Port": 1883, "Id": "device-2", "Username": null, "Password": null, "Tls": false, "QoS": 1, "ReconnectDelayMs": 30000, "ReconnectWithClientSession": true, "ConfigState": "Generated", "RootTopic": "moryx/device-2" }Endpoint feature
Example 1 :
Example 2: