diff --git a/.github/workflows/ReleaseNotes.md b/.github/workflows/ReleaseNotes.md index 7c2ecca2..8b92cf20 100644 --- a/.github/workflows/ReleaseNotes.md +++ b/.github/workflows/ReleaseNotes.md @@ -1,32 +1,2 @@ -We have joined the .NET Foundation! - -Version 4 comes with a new API so a lot of breaking changes should be expected. -Checkout the upgrade guide (https://github.com/dotnet/MQTTnet/wiki/Upgrading-guide) for an overview of the changes. -Checkout the new samples (https://github.com/dotnet/MQTTnet/tree/feature/master/Samples) how to use the new API. The wiki only remains for version 3 of this library. - -Preview builds of this library are available at: https://www.myget.org/feed/mqttnet/package/nuget/MQTTnet - -* [Core] Improved memory management when working with large payloads. -* [Core] Added support for .NET 6.0. -* [Core] nuget packages are now created by MSBuild including more information (i.e. commit hash). -* [Client] Exposed socket linger state in options. -* [Client] The OS will now choose the best TLS version to use. It is no longer fixed to 1.3 etc. (thanks to @patagonaa, #1271). -* [Client] Added support for _ServerKeepAlive_ (MQTTv5). -* [Client] Exposed user properties and reason string in subscribe result. -* [Client] Exposed user properties and reason string in unsubscribe result. -* [Client] Migrated application message handler to a regular .NET event (BREAKING CHANGE!). -* [Client] The will message is longer a regular application message due to not supported properties by the will message (BREAKING CHANGE!). -* [Client] Timeouts are no longer handled inside the library. Each method (Connect, Publish etc.) supports a cancellation token so that custom timeouts can and must be used (BREAKING CHANGE!). -* [Client] Exposed certificate revocation mode on options (@andyolivares). -* [Server] Exposed socket linger state in options. -* [Server] Added support for returning individual subscription errors (#80 thanks to @jimch) -* [Server] Improved topic filter comparisons (support for $). -* [Server] Added more MQTTv5 response information to all interceptors (BREAKING CHANGE!). -* [Server] Improved session management for MQTT v5 (#1294, thanks to @logicaloud). -* [Server] All interceptors and events are migrated from interfaces to simple events. All existing APIs are availble but must be migrated to corresponding events (BREAKING CHANGE!). -* [Server] Removed all interceptor and event interfaces including the delegate implementations etc. (BREAKING CHANGE!). -* [Server] Renamed a lot of classes and adjusted namespaces (BREAKING CHANGE!). -* [Server] Introduced a new queueing approach for internal message process (packet bus). -* [Server] For security reasons the default endpoint (1883) is no longer enabled by default (BREAKING CHANGE!). -* [Server] Added support for choosing the cipher suite (thanks to @TimSiefert). -* [Nuget] Added method summaries etc. to nuget packages (thanks to @SpringHgui). \ No newline at end of file +* [Client] Fixed MQTTv5 protocol violation in PUBLISH packets (#1423). +* [Client] Added missing "WithWill..." methods in _MqttClientOptionsBuilder_. \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f8767c3c..548826f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,8 +3,7 @@ name: CI on: [push, pull_request] env: - ASSEMBLY_VERSION: "4.0.0.${{github.run_number}}" - NUGET_VERSION: "4.0.0.${{github.run_number}}" + VERSION: "4.0.1.${{github.run_number}}" jobs: build: @@ -40,7 +39,7 @@ jobs: run: msbuild MQTTnet.sln /t:Restore /p:Configuration="Release" /verbosity:m - name: Build solution - run: msbuild MQTTnet.sln /t:Build /p:Configuration="Release" /verbosity:m /p:FileVersion=${{ env.ASSEMBLY_VERSION }} /p:AssemblyVersion=${{ env.ASSEMBLY_VERSION }} /p:PackageVersion=${{ env.NUGET_VERSION }} /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=${{ github.workspace }}\certificate.snk + run: msbuild MQTTnet.sln /t:Build /p:Configuration="Release" /verbosity:m /p:FileVersion=${{ env.VERSION }} /p:AssemblyVersion=${{ env.VERSION }} /p:PackageVersion=${{ env.VERSION }} /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=${{ github.workspace }}\certificate.snk - name: Collect nuget Packages uses: actions/upload-artifact@v2 diff --git a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs index 3ed60a24..d8568770 100644 --- a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs +++ b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs @@ -393,6 +393,17 @@ namespace MQTTnet.Client _options.WillPayload = willPayload; return this; } + + public MqttClientOptionsBuilder WithWillPayload(string willPayload) + { + if (string.IsNullOrEmpty(willPayload)) + { + return WithWillPayload((byte[])null); + } + + _options.WillPayload = Encoding.UTF8.GetBytes(willPayload); + return this; + } public MqttClientOptionsBuilder WithWillQualityOfServiceLevel(MqttQualityOfServiceLevel willQualityOfServiceLevel) { @@ -405,5 +416,46 @@ namespace MQTTnet.Client _options.WillTopic = willTopic; return this; } + + public MqttClientOptionsBuilder WithWillRetain(bool willRetain = true) + { + _options.WillRetain = willRetain; + return this; + } + + public MqttClientOptionsBuilder WithWillContentType(string willContentType) + { + _options.WillContentType = willContentType; + return this; + } + + public MqttClientOptionsBuilder WithWillCorrelationData(byte[] willCorrelationData) + { + _options.WillCorrelationData = willCorrelationData; + return this; + } + + public MqttClientOptionsBuilder WithWillResponseTopic(string willResponseTopic) + { + _options.WillResponseTopic = willResponseTopic; + return this; + } + + public MqttClientOptionsBuilder WithWillPayloadFormatIndicator(MqttPayloadFormatIndicator willPayloadFormatIndicator) + { + _options.WillPayloadFormatIndicator = willPayloadFormatIndicator; + return this; + } + + public MqttClientOptionsBuilder WithWillUserProperty(string name, string value) + { + if (_options.WillUserProperties == null) + { + _options.WillUserProperties = new List(); + } + + _options.WillUserProperties.Add(new MqttUserProperty(name, value)); + return this; + } } } \ No newline at end of file diff --git a/Source/MQTTnet/Formatter/V5/MqttV5PropertiesWriter.cs b/Source/MQTTnet/Formatter/V5/MqttV5PropertiesWriter.cs index 3307b661..6b274bba 100644 --- a/Source/MQTTnet/Formatter/V5/MqttV5PropertiesWriter.cs +++ b/Source/MQTTnet/Formatter/V5/MqttV5PropertiesWriter.cs @@ -84,6 +84,11 @@ namespace MQTTnet.Formatter.V5 { // If absent, the Application Message does not expire. // This library uses 0 to indicate no expiration. + if (value == 0) + { + return; + } + WriteAsFourByteInteger(MqttPropertyId.MessageExpiryInterval, value); }