Skip to content

Commit

Permalink
Merge branch 'master' into 1781-hot-reload-for-certificate-authentica…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
chkr1011 authored Aug 19, 2023
2 parents 6988e8c + c537d29 commit acc5aff
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
* [Client] Fixed _PlatformNotSupportedException_ when using Blazor (#1755, thanks to @Nickztar).
* [Client] Added hot reload of client certificates (#1781).
* [Client] Added several new option builders and aligned usage (#1781, BREAKING CHANGE!).
* [Client] Fixed wrong logging of obsolete feature when connection was not successful (#1801, thanks to @ramonsmits).
* [Client] Fixed _NullReferenceException_ when performing several actions when not connected (#1800, thanks to @ramonsmits).
* [Server] Fixed _NullReferenceException_ in retained messages management (#1762, thanks to @logicaloud).
* [Server] Exposed new option which allows disabling packet fragmentation (#1753).
* [Server] Expired sessions will no longer be used when a client connects (#1756).
* [Server] Fixed an issue in connection handling for ASP.NET connections (#1819, thanks to @CZEMacLeod).
7 changes: 5 additions & 2 deletions Source/MQTTnet.AspnetCore/MqttConnectionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ public MqttConnectionContext(MqttPacketFormatterAdapter packetFormatterAdapter,
PacketFormatterAdapter = packetFormatterAdapter ?? throw new ArgumentNullException(nameof(packetFormatterAdapter));
_connection = connection ?? throw new ArgumentNullException(nameof(connection));

_input = connection.Transport.Input;
_output = connection.Transport.Output;
if (!(_connection is TcpConnection tcp) || tcp.IsConnected)
{
_input = connection.Transport.Input;
_output = connection.Transport.Output;
}
}

public long BytesReceived { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,27 @@ public async Task Return_Non_Success()
Assert.AreEqual(response.UserProperties[0].Value, "Value");
}
}

[TestMethod]
public async Task Throw_Proper_Exception_When_Not_Connected()
{
try
{
var mqttFactory = new MqttFactory();
using (var mqttClient = mqttFactory.CreateMqttClient())
{
await mqttClient.SubscribeAsync("test", MqttQualityOfServiceLevel.AtLeastOnce);
}
}
catch (MqttCommunicationException exception)
{
if (exception.Message == "The client is not connected.")
{
return;
}
}

Assert.Fail();
}
}
}
13 changes: 6 additions & 7 deletions Source/MQTTnet/Client/MqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,14 @@ public async Task<MqttClientSubscribeResult> SubscribeAsync(MqttClientSubscribeO
MqttTopicValidator.ThrowIfInvalidSubscribe(topicFilter.Topic);
}

ThrowIfDisposed();
ThrowIfNotConnected();

if (Options.ValidateFeatures)
{
MqttClientSubscribeOptionsValidator.ThrowIfNotSupported(options, _adapter.PacketFormatterAdapter.ProtocolVersion);
}

ThrowIfDisposed();
ThrowIfNotConnected();

var subscribePacket = MqttPacketFactories.Subscribe.Create(options);
subscribePacket.PacketIdentifier = _packetIdentifierProvider.GetNextPacketIdentifier();

Expand Down Expand Up @@ -465,11 +465,10 @@ async Task<MqttClientConnectResult> Authenticate(IMqttChannelAdapter channelAdap
// did send a proper ACK packet with a non success response.
if (options.ThrowOnNonSuccessfulConnectResponse)
{
_logger.Warning(
"Client will now throw an _MqttConnectingFailedException_. This is obsolete and will be removed in the future. Consider setting _ThrowOnNonSuccessfulResponseFromServer=False_ in client options.");

if (result.ResultCode != MqttClientConnectResultCode.Success)
{
_logger.Warning(
"Client will now throw an _MqttConnectingFailedException_. This is obsolete and will be removed in the future. Consider setting _ThrowOnNonSuccessfulResponseFromServer=False_ in client options.");
throw new MqttConnectingFailedException($"Connecting with MQTT server failed ({result.ResultCode}).", null, result);
}
}
Expand Down Expand Up @@ -1060,4 +1059,4 @@ async Task TrySendKeepAliveMessages(CancellationToken cancellationToken)
}
}
}
}
}
6 changes: 6 additions & 0 deletions Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,12 @@ public MqttClientOptionsBuilder WithWillRetain(bool willRetain = true)
return this;
}

public MqttClientOptionsBuilder WithWillMessageExpiryInterval(uint willMessageExpiryInterval)
{
_options.WillMessageExpiryInterval = willMessageExpiryInterval;
return this;
}

public MqttClientOptionsBuilder WithWillTopic(string willTopic)
{
_options.WillTopic = willTopic;
Expand Down

0 comments on commit acc5aff

Please sign in to comment.