mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-21 04:03:05 +08:00
Add ClientId for application messages published by the server.
This commit is contained in:
@@ -4,6 +4,8 @@ namespace MQTTnet.Server
|
|||||||
{
|
{
|
||||||
public interface IMqttServerOptions
|
public interface IMqttServerOptions
|
||||||
{
|
{
|
||||||
|
string ClientId { get; set; }
|
||||||
|
|
||||||
bool EnablePersistentSessions { get; }
|
bool EnablePersistentSessions { get; }
|
||||||
|
|
||||||
int MaxPendingMessagesPerClient { get; }
|
int MaxPendingMessagesPerClient { get; }
|
||||||
@@ -19,6 +21,6 @@ namespace MQTTnet.Server
|
|||||||
MqttServerTcpEndpointOptions DefaultEndpointOptions { get; }
|
MqttServerTcpEndpointOptions DefaultEndpointOptions { get; }
|
||||||
MqttServerTlsTcpEndpointOptions TlsEndpointOptions { get; }
|
MqttServerTlsTcpEndpointOptions TlsEndpointOptions { get; }
|
||||||
|
|
||||||
IMqttServerStorage Storage { get; }
|
IMqttServerStorage Storage { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,7 +364,13 @@ namespace MQTTnet.Server
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var interceptorContext = new MqttApplicationMessageInterceptorContext(sender?.ClientId, applicationMessage);
|
var senderClientId = sender?.ClientId;
|
||||||
|
if (sender == null)
|
||||||
|
{
|
||||||
|
senderClientId = _options.ClientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
var interceptorContext = new MqttApplicationMessageInterceptorContext(senderClientId, applicationMessage);
|
||||||
await interceptor.InterceptApplicationMessagePublishAsync(interceptorContext).ConfigureAwait(false);
|
await interceptor.InterceptApplicationMessagePublishAsync(interceptorContext).ConfigureAwait(false);
|
||||||
return interceptorContext;
|
return interceptorContext;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public MqttServerTlsTcpEndpointOptions TlsEndpointOptions { get; } = new MqttServerTlsTcpEndpointOptions();
|
public MqttServerTlsTcpEndpointOptions TlsEndpointOptions { get; } = new MqttServerTlsTcpEndpointOptions();
|
||||||
|
|
||||||
|
public string ClientId { get; set; }
|
||||||
|
|
||||||
public bool EnablePersistentSessions { get; set; }
|
public bool EnablePersistentSessions { get; set; }
|
||||||
|
|
||||||
public int MaxPendingMessagesPerClient { get; set; } = 250;
|
public int MaxPendingMessagesPerClient { get; set; } = 250;
|
||||||
|
|||||||
@@ -147,6 +147,15 @@ namespace MQTTnet.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the client ID which is used when publishing messages from the server directly.
|
||||||
|
/// </summary>
|
||||||
|
public MqttServerOptionsBuilder WithClientId(string value)
|
||||||
|
{
|
||||||
|
_options.ClientId = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public IMqttServerOptions Build()
|
public IMqttServerOptions Build()
|
||||||
{
|
{
|
||||||
return _options;
|
return _options;
|
||||||
|
|||||||
Reference in New Issue
Block a user