Skip to main content

Create a Subscription

public OpcUaSubscription createSubscription(double publishingIntervalMs);
Prerequisite Reading / Supplementary Materials

Parameters​

ParametersDefaultNote
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​

CategoryPropertyTypeAccessDescription
IdentifiersgetSubscriptionId()intRSubscription ID from the server's perspective
handle()intRC-layer handle (for debugging)
getSession()OpcUaSessionRSession
ConfigurationgetPublishingIntervalMs()doubleRActual publishing interval (revised)
setPublishingEnabled(boolean)Enums.StatusCodeWEnable or disable publishing for the entire subscription
MonitoredItemssize()intRCurrent MI count
getMonitoredNodeIds()List<String>RSnapshot of all current MI NodeIds

OpcUaSubscription Public Methods​

MethodsNote
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.

Next Step​