Skip to content

Conversation

@longkerdandy
Copy link
Owner

This PR implements message ordering improvements including:

  1. Added IsSeqConsecutive and IsCached properties to SparkplugMessageEventArgs
  2. Updated MessageOrderingService to handle sequence checking
  3. Added comprehensive tests for message ordering functionality
  4. Improved code comments and fixed typos

All tests are passing.

@longkerdandy longkerdandy requested a review from Copilot November 10, 2025 07:14
@longkerdandy longkerdandy self-assigned this Nov 10, 2025
@longkerdandy longkerdandy added the enhancement New feature or request label Nov 10, 2025
@longkerdandy longkerdandy added this to the Milestone v1.0.0 milestone Nov 10, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the Sparkplug Host Application Message Ordering feature as specified in the Sparkplug protocol. The update ensures messages with sequence numbers (NDATA/DDATA) are processed in the correct sequential order, with support for handling out-of-order messages through caching and reordering timeouts.

Key changes:

  • Added message ordering service with configurable timeout and rebirth request capabilities
  • Unified event argument types by introducing SparkplugMessageEventArgs to replace separate EdgeNodeMessageEventArgs and DeviceMessageEventArgs
  • Updated SparkplugHostApplication constructor to accept IMemoryCache and ILoggerFactory instead of ILogger

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
SparklerNet.csproj Updated version to 0.9.5-dev and added Microsoft.Extensions.Caching.Memory package dependency
AssemblyInfo.cs Added InternalsVisibleTo attribute for test project access
SparkplugHostApplication.cs Refactored to use unified event args, integrated message ordering service, and added rebirth command support
SparkplugHostApplicationExtensions.cs New extension methods for sending rebirth commands to edge nodes and devices
MessageOrderingService.cs Core implementation of message ordering logic with caching and timeout handling
IMessageOrderingService.cs Interface definition for message ordering service
SparkplugClientOptions.cs Added configuration options for message ordering feature
MqttClientOptionsExtension.cs Added extension method to extract broker URL from MQTT client options
SparkplugMessageEventArgs.cs New unified event args class replacing separate edge node and device event args
SparkplugMessageEvents.cs Updated event types to use unified SparkplugMessageEventArgs
EdgeNodeMessageEventArgs.cs Removed (replaced by unified event args)
DeviceMessageEventArgs.cs Removed (replaced by unified event args)
MessageOrderingServiceTests.cs Comprehensive tests for message ordering functionality
SimpleHostApplication.cs Refactored to use new constructor signature and extension methods
Program.cs New entry point extracted from SimpleHostApplication
README.md Updated to mark message ordering feature as completed

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,4 @@
using System.Runtime.CompilerServices;

// Make internal memebers visible to test project
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'memebers' to 'members'.

Suggested change
// Make internal memebers visible to test project
// Make internal members visible to test project

Copilot uses AI. Check for mistakes.
/// <summary>
/// A simple Sparkplug host application implementation
/// </summary>
/// <summary>
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate XML documentation summary tags. Remove one of the duplicate <summary> blocks as only one summary should be present per class.

Suggested change
/// A simple Sparkplug host application implementation
/// </summary>
/// <summary>

Copilot uses AI. Check for mistakes.
// Safety check: ensure we have a timer even if the new message is not the first one
// This prevents pending messages from being stuck if the timer was lost due to concurrent operations
_reorderTimers.TryAdd(timerKey,
new Timer(OnReorderTimeout, timerKey, _options.SeqReorderTimeout, Timeout.Infinite));
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disposable 'Timer' is created but not disposed.

Copilot uses AI. Check for mistakes.
@longkerdandy longkerdandy requested a review from Copilot November 10, 2025 07:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 10 comments.

Comments suppressed due to low confidence (2)

SparklerNet/Core/Options/SparkplugClientOptions.cs:1

  • [nitpick] The documentation mentions potential delays being 'much longer' than SeqReorderTimeout but doesn't provide guidance on what 'much longer' means or how to estimate the actual delay. Consider adding more specific guidance or examples to help users understand the performance implications.
using MQTTnet.Packets;

SparklerNet/HostApplication/SparkplugHostApplication.cs:1

  • The phrase 'Application self's STATE topic' should be 'Application's self STATE topic' or 'Host Application's STATE topic' for better grammatical clarity.
using System.Diagnostics.CodeAnalysis;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@longkerdandy longkerdandy merged commit e12a286 into main Nov 10, 2025
4 checks passed
@longkerdandy longkerdandy deleted the feature/message-ordering branch November 10, 2025 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants