dotnet / MQTTnet

MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
MIT License
4.5k stars 1.07k forks source link

Use IConnectionFactory to create ConnectionContext to replace SocketConnection #2101

Closed xljiulang closed 4 days ago

xljiulang commented 2 weeks ago

Describe the feature request

  1. Register Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionFactory as IConnectionFactory service with DI.
  2. Modify the CreateClientAdapter method of the IMqttClientAdapterFactory interface to ValueTask<IMqttChannelAdapter>CreateClientAdapterAsync.
  3. MqttClientConnectionContextFactory injects IConnectionFactory and use IConnectionFactory to create ConnectionContext.
  4. Delete SocketAwaitable.cs, SocketConnection.cs, SocketReceiver.cs and SocketSender.cs

Which project is your feature request related to?

Describe the solution you'd like

Hi @chkr1011 I have tried to complete the modification at https://github.com/xljiulang/MQTTnet/commit/897c551d8cb9ef0e6d47380f4a0460c108730b31. At present, I feel that the only shortcoming is that SocketConnectionFactory only supports IPEndPoint. There are still flaws in my implementation of compatible processing of DnsEndPoint.

Finally, is it necessary to make a pull request for my changes?

xljiulang commented 1 week ago

I continued to refactor the MQTTnet.AspNetCore project https://github.com/dotnet/MQTTnet/compare/master...xljiulang:MQTTnet:master

  1. Add IMqttServerBuilder and IMqttClientBuilder.
  2. The extension of ServiceCollection only retains two methods: IMqttServerBuilder AddMqttServer(IServiceCollection) and IMqttClientBuilder AddMqttClient(IServiceCollection).
  3. Provide IMqttServerBuilder with some extension methods needed in the process of creating MqttServer
  4. Provide IMqttClientBuilder with some extension methods needed in the process of creating IMqttClientFactory
  5. Rename and internalize other implementation types, and use InternalsVisibleToAttribute to expose them to the specified assembly.