Add SuperSocket.MQTT.Client with shared pipeline filter and E2E tests#21
Add SuperSocket.MQTT.Client with shared pipeline filter and E2E tests#21kerryjiang merged 5 commits intomasterfrom
Conversation
Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
| /// <summary> | ||
| /// Encodes MQTT packets to bytes for transmission. | ||
| /// </summary> | ||
| public static class MQTTPacketEncoder |
There was a problem hiding this comment.
should implement the interface IPackageEncoder
There was a problem hiding this comment.
Implemented IPackageEncoder<MQTTPacket> interface in commit 89ffcf9.
| { | ||
| return builder | ||
| .UsePipelineFilter<MQTTPipelineFilter>() | ||
| .UsePipelineFilterFactory<MQTTPipelineFilterFactory>() |
There was a problem hiding this comment.
UsePipelineFilter() should be enough, why do you want to use UsePipelineFilterFactory?
There was a problem hiding this comment.
Reverted to UsePipelineFilter<MQTTPipelineFilter>() and removed MQTTPipelineFilterFactory in commit 89ffcf9. The Decoder property now falls back to a static singleton if not set externally.
| // Add all command classes from the current assembly | ||
| options.AddCommandAssembly(typeof(MQTTPacket).Assembly); | ||
| // Add all command classes from the Server assembly | ||
| options.AddCommandAssembly(typeof(SuperSocketHostBuilderExtensions).Assembly); |
There was a problem hiding this comment.
current executing assembly can be used here
There was a problem hiding this comment.
Changed to Assembly.GetExecutingAssembly() in commit 89ffcf9.
| /// </summary> | ||
| public MQTTPipelineFilter() | ||
| { | ||
| Decoder = new MQTTPacketDecoder(); |
There was a problem hiding this comment.
singleton MQTTPacketDecoder instance should be use here because MQTTPacketDecoder is stateless for different MQTTPipelineFilter instances
There was a problem hiding this comment.
Updated to use a singleton _sharedDecoder static field. The Decoder getter now returns _decoder ?? _sharedDecoder to ensure the singleton is always used as fallback. Commit 89ffcf9.
…decoder, use executing assembly Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
| } | ||
|
|
||
| private async ValueTask SendPacketAsync(MQTTPacket packet) | ||
| { |
There was a problem hiding this comment.
the encoder should be assigned to pipeline filter, and send package directly using _client
There was a problem hiding this comment.
Removed the SendPacketAsync helper method and now using _client.SendAsync(MQTTPacketEncoder.Default, packet) directly in commit a8abb9d.
| public class MQTTClient : IAsyncDisposable | ||
| { | ||
| private readonly IEasyClient<MQTTPacket> _client; | ||
| private readonly MQTTPacketEncoder _encoder = new MQTTPacketEncoder(); |
There was a problem hiding this comment.
The encoder should be singleton
There was a problem hiding this comment.
Made MQTTPacketEncoder a singleton with public static readonly MQTTPacketEncoder Default = new MQTTPacketEncoder() in commit a8abb9d.
Co-authored-by: kerryjiang <456060+kerryjiang@users.noreply.github.com>
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.