Skip to content

feat(opcua): configurable monitored-item queue size to retain queued values - #2715

Merged
sruehl merged 5 commits into
apache:developfrom
zylklab:feature/opcua-subscription-queue-and-batching
Aug 27, 2026
Merged

feat(opcua): configurable monitored-item queue size to retain queued values#2715
sruehl merged 5 commits into
apache:developfrom
zylklab:feature/opcua-subscription-queue-and-batching

Conversation

@tirsodelrey

Copy link
Copy Markdown
Contributor

Summary

Adds a 'subscription-queue-size' connection option to the OPC UA driver, letting a subscription keep more than the latest value per monitored item beween publishes. Defaults to '1', so existing behavior is unchanged.

Motivation

For a change-of-state subscription, the server samples a monitored item and queues the values it observes between two publishes. Today the driver hard-codes the monitored-item queue size to 1 with discardOldest = true, so only the most recent value survives each publish cycle, every intermediate change is dropped server-side before it ever reaches the
client. There is currently no way to capture those intermediate values (unless using a cyclic-type subscription)

This is only relevant when an item is sampled faster than the subscription publishes. With per-tag sampling already in place, a change-of-state tag can be told to sample at the server's fastest rate while still publishing at a fixed rate.

What changes

Behavior is gated on subscription-queue-size > 1; with the default 1 nothing below
changes.

  1. Config — new @ConfigurationParameter("subscription-queue-size") (@LongDefaultValue(1)) on OpcuaConfiguration.
  2. Sampling — for a change-of-state tag with no explicit duration, request the server's fastest sampling (samplingInterval = 0.0) so intermediate values actually accumulate in the queue between publishes. Tags with an explicit rate, cyclic tags, and event tags keep their current per-tag sampling.
  3. Queue size — the requested depth is passed to MonitoringParameters instead of the hard-coded 1.
  4. Notification fan-outonMonitoredValue no longer collapses a publish into a single name-keyed event (which would overwrite when the same tag appears more than once, i.e. when the queue actually held multiple values). It accumulates a batch and flushes it as an event before a duplicate tag would overwrite, so every queued value is delivered. The common case (each tag once) still produces a single event.

Backward compatibility

With subscription-queue-size = 1 (the default) there is at most one value per item per publish: the 0.0-sampling branch is not taken, the queue size is 1 as before, and the fan-out produces exactly one event

Notes

The effective depth is bounded by the server's RevisedQueueSize; a server may cap the requested size (e.g. to 2). The driver delivers whatever the server actually queues without dropping; anything beyond the revised depth is discarded server-side (discardOldest).

…values

Adds a 'subscription-queue-size' connection option (default 1, so existing
behavior is unchanged). When set >1:

- change-of-state monitored items are sampled at the server's fastest rate
  (samplingInterval 0.0) so intermediate values accumulate between publishes;
- the requested depth is used as the monitored item's queue size instead of
  the hard-coded 1;
- onMonitoredValue fans DataChangeNotifications out without dropping duplicates:
  a single (name-keyed) event cannot hold two values for one tag, so the batch
  is flushed before a duplicate would overwrite it, keeping every queued value.

With the default of 1 there is at most one value per item per publish, so the
new paths are inert and behavior is byte-for-byte identical to before.
@sruehl
sruehl requested a balanced review from Copilot August 26, 2026 13:36
@sruehl

sruehl commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

@tirsodelrey could it be that you based this on an old sha?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds configurable OPC UA monitored-item queue depth to retain intermediate subscription values.

Changes:

  • Adds the subscription-queue-size option.
  • Adjusts change-of-state sampling and monitored-item queue creation.
  • Fans out queued data-change notifications without overwriting duplicate tags.

Reviewed changes

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

File Description
OpcuaConfiguration.java Defines the queue-size option.
OpcuaConnection.java Passes queue size into subscriptions.
OpcuaSubscriptionHandle.java Configures sampling, queueing, and notification batching.
OpcuaConfigurationTest.java Tests the configuration accessor.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@tirsodelrey

Copy link
Copy Markdown
Contributor Author

@tirsodelrey could it be that you based this on an old sha?

@sruehl Yes, it was branched from an older develop. I forgot to check for any updates before pushing. I've resolved the merge conflict, I hope it is OK now.

@sruehl

sruehl commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

sure, did you see the review comments?

@tirsodelrey

Copy link
Copy Markdown
Contributor Author

@sruehl Yes, Copilot is pretty spot on. I'm addressing these issues now and will push a commit ASAP.

@sruehl

sruehl commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

FYI: I push a update to the ads testsuite in a couple of minutes just in case you are working on the suite atm. I'll let you know once that hits develop edit: wrong PR

[zylk] Tirso del Rey added 2 commits August 26, 2026 18:00
- validate the configured queue size against the OPC UA UInt32 range and
  reject out-of-range values up front, instead of failing later during
  message encoding;
- apply the queue depth only to change-of-state monitored items; event and
  cyclic items keep queue size 1 (event notifications are fanned out through
  a name-keyed map that cannot retain duplicates, and cyclic items never
  sample faster than they publish);
- test the queue-size option through ConfigurationFactory (default 1 and an
  explicit value) instead of setting the field reflectively.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 5 out of 5 changed files in this pull request and generated 1 comment.

…compatibility.

Adding the queue-size parameter to the constructor had replaced the six-argument constructor instead of overloading, thus breaking compatibility with clients.

Added a 3rd constructor that keeps a 6-arg signature
@sruehl
sruehl merged commit 5e2819f into apache:develop Aug 27, 2026
1 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants