Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring MQTTnet.AspNetCore #2103

Open
wants to merge 91 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
897c551
Use IConnectionFactory to create ConnectionContext to replace SocketC…
xljiulang Nov 7, 2024
f38cca3
Refactoring AspNetMQTT
xljiulang Nov 12, 2024
d8c94bd
Separate AspNetCoreMqttServerAdapter from MqttConnectionHandler
xljiulang Nov 13, 2024
73502e4
TryAdd IConnectionFactory as Singleton
xljiulang Nov 13, 2024
3a641ab
Add some remarks
xljiulang Nov 13, 2024
91763ae
Add AspNetCoreMqttNetLogger
xljiulang Nov 13, 2024
9c14222
Delayed start of AspNetCoreMqttServer
xljiulang Nov 13, 2024
2372352
Using fields to cache IHttpContextFeature
xljiulang Nov 13, 2024
8d96e19
Update Server_ASP_NET_Samples
xljiulang Nov 13, 2024
ad5c798
Use ActivatorUtilities to create TMQttServerWrapper
xljiulang Nov 13, 2024
7f95f02
Add IMqttServerBuilder
xljiulang Nov 13, 2024
7b44ea2
Add IMqttClientBuilder
xljiulang Nov 13, 2024
73c1365
Conditionally load SocketConnectionFactoryAssembly
xljiulang Nov 13, 2024
2c10d2c
Add LICENSE
xljiulang Nov 13, 2024
6cda003
DynamicallyAccessedMembers
xljiulang Nov 13, 2024
faaadbd
Inject IOptions<MqttServerOptionsBuilder>
xljiulang Nov 13, 2024
13c9198
Change the namespace to MQTTnet.AspNetCore
xljiulang Nov 13, 2024
b8d8abb
await for_aspNetCoreMqttServer.StartAsync
xljiulang Nov 14, 2024
64ed638
enable Nullable
xljiulang Nov 14, 2024
3526212
Always dispose _connection of AspNetCoreMqttChannelAdapter
xljiulang Nov 14, 2024
b4b0b04
UseTls
xljiulang Nov 14, 2024
d9e02ce
Restore the IMqttClientAdapterFactory interface
xljiulang Nov 15, 2024
b5019bd
Calculate the property values ​​when constructing MqttChannel
xljiulang Nov 15, 2024
c206a4a
MqttServerChannelAdapter is modified to inherit MqttChannel
xljiulang Nov 15, 2024
0a216a9
Add ClientConnectionContext.WebSocket
xljiulang Nov 15, 2024
580257a
Add LICENSE
xljiulang Nov 15, 2024
4f6b7ae
Add support for CreateLowLevelMqttClient
xljiulang Nov 15, 2024
b25159b
AddMqttClient: Use AspNetCoreMqttClientAdapterFactory as the default …
xljiulang Nov 16, 2024
ecb404f
Check that UseMqtt() and MapMqtt() are used.
xljiulang Nov 16, 2024
858a914
AspNetCoreMqttServerAdapter: Logging when MqttServerOptions are ignored
xljiulang Nov 16, 2024
fedb631
Add IMqttServerBuilder.AddMqttServerAdapter() extensions
xljiulang Nov 16, 2024
67239cd
Register MqttServerOptions and MqttServerStopOptions as services
xljiulang Nov 16, 2024
e03b9b1
IMqttBuilder: Add IMqttBuilder.UseAspNetCoreMqttNetLogger() extension
xljiulang Nov 16, 2024
014a50b
Remove some dead code.
xljiulang Nov 16, 2024
ad62877
Apply the properties of MqttClientTcpOptions to the Socket
xljiulang Nov 16, 2024
c49beb0
TlsConnectionFeature supports passing in ClientCertificate
xljiulang Nov 17, 2024
4c55368
Add support for MqttPacketInspector
xljiulang Nov 17, 2024
34a4db2
Add route syntax for pattern parameter.
xljiulang Nov 17, 2024
6dc18e1
Add KestrelServerOptions.ListenMqtt() extensions.
xljiulang Nov 17, 2024
67dfda4
Optimize the implementation of ListenMqtt.
xljiulang Nov 17, 2024
5813a13
Adapt MqttServerTlsTcpEndpointOptions to HttpsConnectionAdapterOptions
xljiulang Nov 17, 2024
7628614
Compatible with the default server certificate.
xljiulang Nov 17, 2024
7d8562a
Supports both MQTT and MQTT over WebSocket on a ConnectionContext.
xljiulang Nov 18, 2024
1bd5949
MqttProtocols adds WebSocket item.
xljiulang Nov 18, 2024
c4d9a22
Make sure services.AddMqttServer() has been called before operating M…
xljiulang Nov 18, 2024
62313c8
Simplify MqttConnectionMiddleware
xljiulang Nov 18, 2024
e087acb
Improve the compatibility of wss connections.
xljiulang Nov 18, 2024
db4614c
Update UnixSocket sample.
xljiulang Nov 18, 2024
acf8ed7
Update benchmark
xljiulang Nov 18, 2024
457dcc1
Enhanced IOptions of MQTT ServiceOptions
xljiulang Nov 19, 2024
358c2c0
add IMqttServerBuilder.ConfigureMqttSocketTransport extension.
xljiulang Nov 19, 2024
02778aa
Simplifying MqttOptionsFactory
xljiulang Nov 19, 2024
b46b357
Optimizing MqttChannel.SendPacketAsync
xljiulang Nov 19, 2024
38eb1c3
Check buffer IsEmpty.
xljiulang Nov 20, 2024
f953d6d
Merge branch 'dotnet:master' into master
xljiulang Nov 30, 2024
ef838f8
Register MqttClientFactory as a service.
xljiulang Nov 30, 2024
fcad255
Merge branch 'dotnet:master' into master
xljiulang Dec 1, 2024
72b42d5
MqttOptionsFactory.Build() -> MqttOptionsFactory.CreateOptions()
xljiulang Dec 2, 2024
b40c8a1
Add MqttBufferWriterPool
xljiulang Dec 2, 2024
4305ad7
Merge branch 'dotnet:master' into master
xljiulang Dec 2, 2024
cb68a13
Merged from the master branch.
xljiulang Dec 2, 2024
a2c014f
Adapt the RemoteEndPoint property.
xljiulang Dec 2, 2024
dad4faa
Add MqttBufferWriterPoolOptions
xljiulang Dec 3, 2024
6f60eae
Add more conditions to the pool of MqttBufferWriterPoolOptions.
xljiulang Dec 3, 2024
cc64f95
Merge branch 'main'
xljiulang Dec 4, 2024
54f0b4d
MqttBufferWriterPool: Implementing the IReadOnlyCollection interface.
xljiulang Dec 4, 2024
ee4de82
ConfigureAwait(false)
xljiulang Dec 4, 2024
b708344
MqttChannel: adapt AllowPacketFragmentation option.
xljiulang Dec 4, 2024
13e8190
Fixed the issue that GetRemoteEndPoint did not use the remoteEndPoint…
xljiulang Dec 4, 2024
4bfd77d
Add some unit tests.
xljiulang Dec 4, 2024
9d9dd44
Add more unit test.
xljiulang Dec 4, 2024
8b7c411
MqttBufferWriterPoolOptions: Renaming properties.
xljiulang Dec 4, 2024
8a3624d
Rename and update benchmark.
xljiulang Dec 5, 2024
06f03cb
Add AspNetCoreTestEnvironment to test environments.
xljiulang Dec 6, 2024
146b161
CreateTestEnvironment -> CreateMQTTnetTestEnvironment
xljiulang Dec 6, 2024
83148ca
Remove Google's connection test to avoid Google being blocked by SNI …
xljiulang Dec 6, 2024
41af5c5
AspNetCoreTestEnvironment: Adapt logger.
xljiulang Dec 6, 2024
f94e17a
wait with timeout.
xljiulang Dec 6, 2024
efcd6ab
AspNetCoreTestEnvironment: Adjust all configurations to be consistent…
xljiulang Dec 6, 2024
b035659
MqttChannel: Exception handling remains consistent with MqttChannelAd…
xljiulang Dec 6, 2024
6171c81
CrossPlatformSocket_Tests: create a localhost web server for remote h…
xljiulang Dec 6, 2024
9a7a8bd
Server-side adaptation of AllowPacketFragmentation options.
xljiulang Dec 7, 2024
e01e5f3
Merge implementation of IsAllowPacketFragmentation.
xljiulang Dec 8, 2024
bffe065
Added UseLogger overloaded method and renamed an internal method.
xljiulang Dec 8, 2024
ca5d13d
Add some extension methods to IMqttChannelAdapter.
xljiulang Dec 8, 2024
8ceba5f
Add IAspNetCoreMqttChannel and remove IAspNetCoreMqttChannelAdapter;
xljiulang Dec 9, 2024
b65c176
MapMqtt: Restricted to WebSocket transport protocol.
xljiulang Dec 9, 2024
51fb185
Adapt MqttServerTcpEndpointBaseOptions to the Socket accepted by kest…
xljiulang Dec 9, 2024
79f4f68
SocketOptionName.ReuseAddress can only be used for listening Socket s…
xljiulang Dec 9, 2024
7139431
Accurately detect the DualMode value of listenSocket.
xljiulang Dec 9, 2024
5c6e128
Merge branch 'dotnet:master' into master
xljiulang Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added UseLogger overloaded method and renamed an internal method.
xljiulang committed Dec 8, 2024

Verified

This commit was signed with the committer’s verified signature.
tsjensen Thomas Jensen
commit bffe06580a4f623d2d10195b50e44168ad519178
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ sealed class PacketFragmentationFeature(Func<IMqttChannelAdapter, bool> allowPac
{
public Func<IMqttChannelAdapter, bool> AllowPacketFragmentationSelector { get; } = allowPacketFragmentationSelector;

public static bool IsAllowPacketFragmentation(IMqttChannelAdapter channelAdapter, MqttServerTcpEndpointBaseOptions? endpointOptions)
public static bool CanAllowPacketFragmentation(IMqttChannelAdapter channelAdapter, MqttServerTcpEndpointBaseOptions? endpointOptions)
{
//if (endpointOptions != null && endpointOptions.AllowPacketFragmentationSelector != null)
//{
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ private void SetAllowPacketFragmentation(ConnectionContext connection, HttpConte

if (packetFragmentationFeature == null)
{
var value = PacketFragmentationFeature.IsAllowPacketFragmentation(this, null);
var value = PacketFragmentationFeature.CanAllowPacketFragmentation(this, null);
SetAllowPacketFragmentation(value);
}
else
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ void UseMiddleware(ListenOptions listenOptions)
tlsConfigure?.Invoke(httpsOptions);
});
}
listenOptions.UseMqtt(protocols, channelAdapter => PacketFragmentationFeature.IsAllowPacketFragmentation(channelAdapter, endpoint));
listenOptions.UseMqtt(protocols, channelAdapter => PacketFragmentationFeature.CanAllowPacketFragmentation(channelAdapter, endpoint));
}
}
}
17 changes: 15 additions & 2 deletions Source/MQTTnet.AspnetCore/MqttBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ public static IMqttBuilder UseAspNetCoreMqttNetLogger(this IMqttBuilder builder)
/// <returns></returns>
public static IMqttBuilder UseMqttNetNullLogger(this IMqttBuilder builder)
{
return builder.UseLogger<MqttNetNullLogger>();
return builder.UseLogger(MqttNetNullLogger.Instance);
}

/// <summary>
@@ -55,6 +55,19 @@ public static IMqttBuilder UseMqttNetNullLogger(this IMqttBuilder builder)
{
builder.Services.Replace(ServiceDescriptor.Singleton<IMqttNetLogger, TLogger>());
return builder;
}
}

/// <summary>
/// Use a logger
/// </summary>
/// <param name="builder"></param>
/// <param name="logger"></param>
/// <returns></returns>
public static IMqttBuilder UseLogger(this IMqttBuilder builder, IMqttNetLogger logger)
{
ArgumentNullException.ThrowIfNull(logger);
builder.Services.Replace(ServiceDescriptor.Singleton(logger));
return builder;
}
}
}
6 changes: 2 additions & 4 deletions Source/MQTTnet.Tests/Mockups/AspNetCoreTestEnvironment.cs
Original file line number Diff line number Diff line change
@@ -50,8 +50,7 @@ private IMqttClientFactory CreateClientFactory()
var services = new ServiceCollection();

var logger = EnableLogger ? (IMqttNetLogger)ClientLogger : MqttNetNullLogger.Instance;
services.AddSingleton(logger);
services.AddMqttClient();
services.AddMqttClient().UseLogger(logger);

return services.BuildServiceProvider().GetRequiredService<IMqttClientFactory>();
}
@@ -94,8 +93,7 @@ private async Task<MqttServer> StartServer(MqttServerOptions serverOptions)
appBuilder.Services.AddSingleton(serverOptions);

var logger = EnableLogger ? (IMqttNetLogger)ServerLogger : new MqttNetNullLogger();
appBuilder.Services.AddSingleton(logger);
appBuilder.Services.AddMqttServer();
appBuilder.Services.AddMqttServer().UseLogger(logger);

appBuilder.WebHost.UseKestrel(k => k.ListenMqtt());
appBuilder.Host.ConfigureHostOptions(h => h.ShutdownTimeout = TimeSpan.FromMilliseconds(500d));