Skip to content

Commit

Permalink
Merge pull request #8 from JonasMH/develop
Browse files Browse the repository at this point in the history
Add uuid to instanceId
  • Loading branch information
JonasMH authored Mar 27, 2022
2 parents 73c706b + 37a600f commit 561d7ef
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ToMqttNet/MqttConnectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ToMqttNet
public class MqttConnectionService : BackgroundService, IMqttConnectionService
{
private readonly ILogger<MqttConnectionService> _logger;
private string _instanceId = Guid.NewGuid().ToString();

public MqttConnectionOptions MqttOptions { get; }
private IManagedMqttClient? _mqttClient;
Expand All @@ -30,7 +31,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
var options = new ManagedMqttClientOptionsBuilder()
.WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
.WithClientOptions(new MqttClientOptionsBuilder()
.WithClientId(MqttOptions.ClientId)
.WithClientId(MqttOptions.ClientId + "-" + _instanceId)
.WithTcpServer(MqttOptions.Server, MqttOptions.Port)
.WithWillMessage(
new MqttApplicationMessageBuilder()
Expand Down

0 comments on commit 561d7ef

Please sign in to comment.