Create a Subscription
public OpcUaSubscription createSubscription(double publishingIntervalMs);
Prerequisite Reading / Supplementary Materials
- Add MonitoredItem Please see Add MonitoredItem.
- For the DataChanged callback field, see DataChanged Callback.
Parameters
| Parameters | Default | Note |
|---|---|---|
| publishingIntervalMs | (No default; required) | The minimum interval for the server to push data; the server may revise (adjust) it. |
Examples
try (OpcUaSubscription sub = ua.createSubscription(500.0)) {
System.out.println("Subscription created with id=" + sub.getSubscriptionId());
System.out.println("Actual interval = " + sub.getPublishingIntervalMs() + "ms");
}
Multiple Subscription Channels
If an app requires both 100 ms high-frequency subscriptions (fitness data) and 5000 ms low-frequency subscriptions (ambient temperature), create 2 separate subscription branches; do not combine them into a single one:
try (OpcUaSubscription fast = ua.createSubscription(100);
OpcUaSubscription slow = ua.createSubscription(5000)) {
fast.add("ns=2;s=AxisPosition", null);
slow.add("ns=2;s=AmbientTemperature", null);
Thread.sleep(60_000);
}
Each subscription has its own release schedule, and they do not affect one another.
OpcUaSubscription Public Attributes
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Identifiers | getSubscriptionId() | int | R | Subscription ID from the server's perspective |
handle() | int | R | C-layer handle (for debugging) | |
getSession() | OpcUaSession | R | Session | |
| Configuration | getPublishingIntervalMs() | double | R | Actual publishing interval (revised) |
setPublishingEnabled(boolean) | Enums.StatusCode | W | Enable or disable publishing for the entire subscription | |
| MonitoredItems | size() | int | R | Current MI count |
getMonitoredNodeIds() | List<String> | R | Snapshot of all current MI NodeIds |
OpcUaSubscription Public Methods
| Methods | Note |
|---|---|
| add(nodeId, Consumer) | Add Order MI |
| add(nodeId, Consumer, AttributeId, samplingMs) | Add Order MI (Full Parameters) |
| addMany(nodeIds, Consumer, AttributeId) | Add in Bulk |
| remove(int handle) | Removal Order MI |
| removeByNodeId(String nodeId) | Press NodeId to remove all matching items MI |
| modify(publishingMs, ...) | Change Subscription Settings |
| setMonitoringMode(mode, miHandles) | Batch Cut Mode |
| setMode(handle, mode) | Cut Order MI mode |
| modifyMonitoredItems(requests) | Batch Change Sampling |
| modifyItem(handle, samplingMs, queueSize, discardOldest) | Amendment MI |
| republish(seqNo) | Request Resend |
| pump(timeoutMs) | Manual Publish |
| close() | Release, Server-side DeleteSubscription |
Event (Java-style)
public final List<Consumer<DataChangeEventArgs>> onDataChanged;
For more information, see DataChanged Callback.