Browse Source

Add new publish overloads.

release/3.x.x
Christian Kratky 6 years ago
parent
commit
f39589a8c1
2 changed files with 17 additions and 7 deletions
  1. +1
    -0
      Build/MQTTnet.nuspec
  2. +16
    -7
      Source/MQTTnet/ApplicationMessagePublisherExtensions.cs

+ 1
- 0
Build/MQTTnet.nuspec View File

@@ -18,6 +18,7 @@
* [Client] Received messages are now processed completely in the worker thread without creating new Tasks. * [Client] Received messages are now processed completely in the worker thread without creating new Tasks.
* [Client] Fixed wrong calculation for sending keep alive packets (thanks to @cstichlberger) * [Client] Fixed wrong calculation for sending keep alive packets (thanks to @cstichlberger)
* [Client] A clean disconnect (via DisconnectAsync) will no longer throw an exception. * [Client] A clean disconnect (via DisconnectAsync) will no longer throw an exception.
* [Client] Added new overloads for quick message publishing.
* [ManagedClient] The managed client is moved to a separate nuget package. * [ManagedClient] The managed client is moved to a separate nuget package.
* [ManagedClient] Added an own message format with extended properties like ID (BREAKING CHANGE). * [ManagedClient] Added an own message format with extended properties like ID (BREAKING CHANGE).
* [ManagedClient] Fixed a loading issue of stored application messages (thanks to @JTrotta). * [ManagedClient] Fixed a loading issue of stored application messages (thanks to @JTrotta).


+ 16
- 7
Source/MQTTnet/ApplicationMessagePublisherExtensions.cs View File

@@ -14,7 +14,7 @@ namespace MQTTnet


foreach (var applicationMessage in applicationMessages) foreach (var applicationMessage in applicationMessages)
{ {
await publisher.PublishAsync(applicationMessage);
await publisher.PublishAsync(applicationMessage).ConfigureAwait(false);
} }
} }


@@ -25,7 +25,7 @@ namespace MQTTnet


foreach (var applicationMessage in applicationMessages) foreach (var applicationMessage in applicationMessages)
{ {
await publisher.PublishAsync(applicationMessage);
await publisher.PublishAsync(applicationMessage).ConfigureAwait(false);
} }
} }


@@ -35,8 +35,7 @@ namespace MQTTnet
if (topic == null) throw new ArgumentNullException(nameof(topic)); if (topic == null) throw new ArgumentNullException(nameof(topic));


return publisher.PublishAsync(builder => builder return publisher.PublishAsync(builder => builder
.WithTopic(topic)
);
.WithTopic(topic));
} }


public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload) public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload)
@@ -46,8 +45,7 @@ namespace MQTTnet


return publisher.PublishAsync(builder => builder return publisher.PublishAsync(builder => builder
.WithTopic(topic) .WithTopic(topic)
.WithPayload(payload)
);
.WithPayload(payload));
} }


public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload, MqttQualityOfServiceLevel qualityOfServiceLevel) public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload, MqttQualityOfServiceLevel qualityOfServiceLevel)
@@ -55,11 +53,22 @@ namespace MQTTnet
if (publisher == null) throw new ArgumentNullException(nameof(publisher)); if (publisher == null) throw new ArgumentNullException(nameof(publisher));
if (topic == null) throw new ArgumentNullException(nameof(topic)); if (topic == null) throw new ArgumentNullException(nameof(topic));


return publisher.PublishAsync(builder => builder
.WithTopic(topic)
.WithPayload(payload)
.WithQualityOfServiceLevel(qualityOfServiceLevel));
}

public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload, MqttQualityOfServiceLevel qualityOfServiceLevel, bool retain)
{
if (publisher == null) throw new ArgumentNullException(nameof(publisher));
if (topic == null) throw new ArgumentNullException(nameof(topic));

return publisher.PublishAsync(builder => builder return publisher.PublishAsync(builder => builder
.WithTopic(topic) .WithTopic(topic)
.WithPayload(payload) .WithPayload(payload)
.WithQualityOfServiceLevel(qualityOfServiceLevel) .WithQualityOfServiceLevel(qualityOfServiceLevel)
);
.WithRetainFlag(retain));
} }


public static Task PublishAsync(this IApplicationMessagePublisher publisher, Func<MqttApplicationMessageBuilder, MqttApplicationMessageBuilder> builder) public static Task PublishAsync(this IApplicationMessagePublisher publisher, Func<MqttApplicationMessageBuilder, MqttApplicationMessageBuilder> builder)


Loading…
Cancel
Save