Skip to content

Commit

Permalink
Updated MQTT
Browse files Browse the repository at this point in the history
- Added TopicPrefix configuration option
- Fixed issue with MTConnectMqttBroker start retry
- Consolidated source code of creating Mqtt Messages into new MTConnectMqttMessage class
- Fixed issue with Hierarchy Format (repeated DataItemId in Topic)
  • Loading branch information
PatrickRitchie committed Mar 13, 2023
1 parent 9b5bd4a commit 469adf4
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 417 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

namespace MTConnect.Configurations
{
/// <summary>
/// Configuration for an MTConnect Shdr > Http Agent
/// </summary>
public interface IMqttAgentApplicationConfiguration : IAgentApplicationConfiguration, IMTConnectMqttClientConfiguration
{
bool RetainMessages { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// TrakHound Inc. licenses this file to you under the MIT license.

using System.Text.Json.Serialization;
using YamlDotNet.Serialization;

namespace MTConnect.Configurations
{
Expand Down Expand Up @@ -49,6 +50,10 @@ public class MqttAgentApplicationConfiguration : AgentApplicationConfiguration,
[JsonPropertyName("mqttFormat")]
public MTConnectMqttFormat MqttFormat { get; set; }

[JsonPropertyName("mqttTopicPrefix")]
[YamlMember(Alias = "mqttTopicPrefix")]
public string TopicPrefix { get; set; }


public MqttAgentApplicationConfiguration()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// TrakHound Inc. licenses this file to you under the MIT license.

using System.Text.Json.Serialization;
using YamlDotNet.Serialization;

namespace MTConnect.Configurations
{
Expand Down Expand Up @@ -49,6 +50,10 @@ public class ShdrMqttAgentApplicationConfiguration : ShdrAgentApplicationConfigu
[JsonPropertyName("mqttFormat")]
public MTConnectMqttFormat MqttFormat { get; set; }

[JsonPropertyName("mqttTopicPrefix")]
[YamlMember(Alias = "mqttTopicPrefix")]
public string TopicPrefix { get; set; }


public ShdrMqttAgentApplicationConfiguration()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ protected override async void OnStartAgentBeforeLoad(IEnumerable<DeviceConfigura
_mqttServer = mqttFactory.CreateMqttServer(mqttServerOptions);

_mqttBroker = new MTConnectMqttBroker(Agent, _mqttServer);
_mqttBroker.Format = _configuration.MqttFormat;
_mqttBroker.RetainMessages = _configuration.RetainMessages;
_mqttBroker.TopicPrefix = _configuration.TopicPrefix;
await _mqttBroker.StartAsync(CancellationToken.None);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ public interface IMTConnectMqttClientConfiguration
bool AllowUntrustedCertificates { get; set; }

int RetryInterval { get; set; }

string TopicPrefix { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class MTConnectMqttClientConfiguration : IMTConnectMqttClientConfiguratio
[JsonPropertyName("retryInterval")]
public int RetryInterval { get; set; }

[JsonPropertyName("topicPrefix")]
public string TopicPrefix { get; set; }


public MTConnectMqttClientConfiguration()
{
Expand Down
Loading

0 comments on commit 469adf4

Please sign in to comment.