mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-19 11:03:07 +08:00
Restore undelivered event.
This commit is contained in:
@@ -407,14 +407,7 @@ namespace MQTTnet.Server.Internal
|
|||||||
}
|
}
|
||||||
|
|
||||||
_logger.Verbose("Client '{0}': Queued application message with topic '{1}'.", clientSession.Id, applicationMessage.Topic);
|
_logger.Verbose("Client '{0}': Queued application message with topic '{1}'.", clientSession.Id, applicationMessage.Topic);
|
||||||
|
|
||||||
// var queuedApplicationMessage = new MqttQueuedApplicationMessage
|
|
||||||
// {
|
|
||||||
// ApplicationMessage = applicationMessage,
|
|
||||||
// SubscriptionQualityOfServiceLevel = checkSubscriptionsResult.QualityOfServiceLevel,
|
|
||||||
// SubscriptionIdentifiers = checkSubscriptionsResult.SubscriptionIdentifiers
|
|
||||||
// };
|
|
||||||
|
|
||||||
var newPublishPacket = _packetFactories.Publish.Create(applicationMessage);
|
var newPublishPacket = _packetFactories.Publish.Create(applicationMessage);
|
||||||
newPublishPacket.QualityOfServiceLevel = checkSubscriptionsResult.QualityOfServiceLevel;
|
newPublishPacket.QualityOfServiceLevel = checkSubscriptionsResult.QualityOfServiceLevel;
|
||||||
newPublishPacket.Properties.SubscriptionIdentifiers.AddRange(checkSubscriptionsResult.SubscriptionIdentifiers);
|
newPublishPacket.Properties.SubscriptionIdentifiers.AddRange(checkSubscriptionsResult.SubscriptionIdentifiers);
|
||||||
@@ -441,15 +434,11 @@ namespace MQTTnet.Server.Internal
|
|||||||
|
|
||||||
if (deliveryCount == 0)
|
if (deliveryCount == 0)
|
||||||
{
|
{
|
||||||
// TODO: Addd event for not delivered publish packets.
|
await _eventContainer.ApplicationMessageNotConsumedEvent.InvokeAsync(() => new MqttApplicationMessageNotConsumedEventArgs
|
||||||
// var undeliveredMessageInterceptor = _options.UndeliveredMessageInterceptor;
|
{
|
||||||
// if (undeliveredMessageInterceptor == null)
|
ApplicationMessage = applicationMessage,
|
||||||
// {
|
SenderClientId = senderClientId
|
||||||
// return;
|
}).ConfigureAwait(false);
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // The delegate signature is the same as for regular message interceptor. So the call is fine and just uses a different interceptor.
|
|
||||||
// await InterceptApplicationMessageAsync(undeliveredMessageInterceptor, sender, applicationMessage).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ namespace MQTTnet.Server.Internal
|
|||||||
public AsyncEvent<MqttServerClientUnsubscribedTopicEventArgs> ClientUnsubscribedTopicEvent { get; } = new AsyncEvent<MqttServerClientUnsubscribedTopicEventArgs>();
|
public AsyncEvent<MqttServerClientUnsubscribedTopicEventArgs> ClientUnsubscribedTopicEvent { get; } = new AsyncEvent<MqttServerClientUnsubscribedTopicEventArgs>();
|
||||||
|
|
||||||
public AsyncEvent<PreparingMqttClientSessionEventArgs> PreparingClientSessionEvent { get; } = new AsyncEvent<PreparingMqttClientSessionEventArgs>();
|
public AsyncEvent<PreparingMqttClientSessionEventArgs> PreparingClientSessionEvent { get; } = new AsyncEvent<PreparingMqttClientSessionEventArgs>();
|
||||||
|
|
||||||
|
public AsyncEvent<MqttApplicationMessageNotConsumedEventArgs> ApplicationMessageNotConsumedEvent { get; } = new AsyncEvent<MqttApplicationMessageNotConsumedEventArgs>();
|
||||||
|
|
||||||
public AsyncEvent<EventArgs> StartedEvent { get; } = new AsyncEvent<EventArgs>();
|
public AsyncEvent<EventArgs> StartedEvent { get; } = new AsyncEvent<EventArgs>();
|
||||||
|
|
||||||
public AsyncEvent<EventArgs> StoppedEvent { get; } = new AsyncEvent<EventArgs>();
|
public AsyncEvent<EventArgs> StoppedEvent { get; } = new AsyncEvent<EventArgs>();
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MQTTnet.Server
|
||||||
|
{
|
||||||
|
public sealed class MqttApplicationMessageNotConsumedEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the application message which was not consumed by any client.
|
||||||
|
/// </summary>
|
||||||
|
public MqttApplicationMessage ApplicationMessage { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the ID of the client which has sent the affected application message.
|
||||||
|
/// </summary>
|
||||||
|
public string SenderClientId { get; internal set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -107,6 +107,12 @@ namespace MQTTnet.Server
|
|||||||
remove => _eventContainer.PreparingClientSessionEvent.RemoveHandler(value);
|
remove => _eventContainer.PreparingClientSessionEvent.RemoveHandler(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public event Func<MqttApplicationMessageNotConsumedEventArgs, Task> ApplicationMessageNotConsumedAsync
|
||||||
|
{
|
||||||
|
add => _eventContainer.ApplicationMessageNotConsumedEvent.AddHandler(value);
|
||||||
|
remove => _eventContainer.ApplicationMessageNotConsumedEvent.RemoveHandler(value);
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsStarted => _cancellationTokenSource != null;
|
public bool IsStarted => _cancellationTokenSource != null;
|
||||||
|
|
||||||
public Task<IList<IMqttClientStatus>> GetClientStatusAsync()
|
public Task<IList<IMqttClientStatus>> GetClientStatusAsync()
|
||||||
|
|||||||
@@ -1027,22 +1027,22 @@ namespace MQTTnet.Tests.Server
|
|||||||
{
|
{
|
||||||
var undeliverd = string.Empty;
|
var undeliverd = string.Empty;
|
||||||
|
|
||||||
throw new NotImplementedException();
|
var server = await testEnvironment.StartServer();
|
||||||
|
server.ApplicationMessageNotConsumedAsync += e =>
|
||||||
|
{
|
||||||
|
undeliverd = e.ApplicationMessage.Topic;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
};
|
||||||
|
|
||||||
// var options = new MqttServerOptionsBuilder().WithUndeliveredMessageInterceptor(
|
var client = await testEnvironment.ConnectClient();
|
||||||
// context => { undeliverd = context.ApplicationMessage.Topic; });
|
|
||||||
//
|
await client.SubscribeAsync("b");
|
||||||
// await testEnvironment.StartServer(options);
|
|
||||||
//
|
await client.PublishAsync("a", null, MqttQualityOfServiceLevel.ExactlyOnce);
|
||||||
// var client = await testEnvironment.ConnectClient();
|
|
||||||
//
|
await Task.Delay(500);
|
||||||
// await client.SubscribeAsync("b");
|
|
||||||
//
|
Assert.AreEqual("a", undeliverd);
|
||||||
// await client.PublishAsync("a", null, MqttQualityOfServiceLevel.ExactlyOnce);
|
|
||||||
//
|
|
||||||
// await Task.Delay(500);
|
|
||||||
//
|
|
||||||
// Assert.AreEqual("a", undeliverd);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user