Table of Contents

KNet for OPC (KNetOPC): current available predicates and transformations

This page describes each predicate and each transformation available in KNetOPC and their configuration properties. For a general introduction to predicates and transformations, how they are applied, and how to configure them in the connector properties file, see Introduction to predicates and transformations.

As in any Kafka Connect pipeline, a predicate is attached to a transformation: a record matches a predicate when the predicate evaluates to true for it. In the examples of this page the standard Filter transformation is used, which drops the records matching its predicate: negate=true inverts the result, so that only the matching records are kept.

All predicates are built on JCOBridge HPA and evaluate records through views over the JVM memory, without copying data between the JVM and the CLR. KNetOPCPredicateValueCompare, KNetOPCPredicateBuiltIn and KNetOPCPredicateBoolean take full advantage of it only with .NET 10 and the Binary encoding type (EncodingType set to 0 in the Source connector), while the other predicates do so with Binary encoding on both .NET 8 and .NET 10; see Performance and runtime requirements. Every predicate and transformation also accepts always.use.full.decoder (default false), which disables the memory views and always uses the full decoder.

Summary

Available predicates:

Predicate Description
KNetOPCPredicateGood Matches records whose OPC-UA StatusCode is Good.
KNetOPCPredicateBad Matches records whose OPC-UA StatusCode is Bad.
KNetOPCPredicateBoolean Matches records whose Boolean node value matches a configured value.
KNetOPCPredicateBuiltIn Matches records whose node value is of one of the configured OPC-UA BuiltInTypes.
KNetOPCPredicateNotOldThan Matches records whose timestamp is not older than a configured number of seconds.
KNetOPCPredicateValueCompare Matches records whose scalar node value satisfies a comparison condition against a configured threshold.

Available transformations:

Transformation Description
KNetOPCTransformationEncodingTypeChange Converts the records to a different OPC-UA encoding type (Binary, Xml or Json).

KNetOPCPredicateGood

Java class: org.mases.knetopc.transformations.predicates.KNetOPCPredicateGood

Matches a record only if the OPC-UA StatusCode of the change notification is Good (i.e. StatusCode.IsGood(statusCode) == true). Use this predicate to ensure only healthy readings reach the Kafka topic.

Note

With the Binary encoding type this predicate evaluates the record through views directly over the JVM memory, on both .NET 8 and .NET 10; see Performance and runtime requirements.

Configuration properties and example

This predicate has no additional configuration properties beyond the common base properties.

Example

Keep only the records with a Good status code:

predicates=IsGood
predicates.IsGood.type=org.mases.knetopc.transformations.predicates.KNetOPCPredicateGood

transforms=KeepGood
transforms.KeepGood.type=org.apache.kafka.connect.transforms.Filter
transforms.KeepGood.predicate=IsGood
transforms.KeepGood.negate=true

KNetOPCPredicateBad

Java class: org.mases.knetopc.transformations.predicates.KNetOPCPredicateBad

Matches a record only if the OPC-UA StatusCode of the change notification is Bad (i.e. StatusCode.IsBad(statusCode) == true). Useful to drop fault or error readings from the main topic, or to route them to a dedicated diagnostic topic with a router transformation attached to this predicate.

Note

With the Binary encoding type this predicate evaluates the record through views directly over the JVM memory, on both .NET 8 and .NET 10; see Performance and runtime requirements.

Configuration properties and example

This predicate has no additional configuration properties beyond the common base properties.

Example

The following example drops the Bad records, since Filter drops the records matching its predicate:

predicates=IsBad
predicates.IsBad.type=org.mases.knetopc.transformations.predicates.KNetOPCPredicateBad

transforms=DropBad
transforms.DropBad.type=org.apache.kafka.connect.transforms.Filter
transforms.DropBad.predicate=IsBad

KNetOPCPredicateBoolean

Java class: org.mases.knetopc.transformations.predicates.KNetOPCPredicateBoolean

Matches a record only if the OPC-UA node value is of Boolean built-in type and its value is equal to the configured boolean.value. Records whose value is not of Boolean type never match.

Note

This predicate takes full advantage of JCOBridge HPA with .NET 10 and the Binary encoding type; see Performance and runtime requirements.

Configuration properties and example
Property Type Required Default Description
boolean.value boolean Yes — The boolean value to match. Set to true to match only records where the node value is true; set to false to match only records where the node value is false.

Example

Keep only the records whose Boolean node value is true:

predicates=IsActive
predicates.IsActive.type=org.mases.knetopc.transformations.predicates.KNetOPCPredicateBoolean
predicates.IsActive.boolean.value=true

transforms=KeepActive
transforms.KeepActive.type=org.apache.kafka.connect.transforms.Filter
transforms.KeepActive.predicate=IsActive
transforms.KeepActive.negate=true

KNetOPCPredicateBuiltIn

Java class: org.mases.knetopc.transformations.predicates.KNetOPCPredicateBuiltIn

Matches a record only if the OPC-UA BuiltInType of the node value is one of the types listed in the builtins configuration property. The predicate checks the type of the value, not its content: use KNetOPCPredicateValueCompare to compare values.

The predicate works on scalar values only: records with array or non-scalar values do not match and an error is logged. The same happens to records whose notification carries no value (a warning is logged) and to records of any OPC-UA type other than MonitoredItemNotification and KNetOPCAlarmEvent.

For KNetOPCAlarmEvent records the type to check is the one of the event field selected with field.name; if the field is not present in the event the record does not match.

Note

This predicate takes full advantage of JCOBridge HPA with .NET 10 and the Binary encoding type; see Performance and runtime requirements.

Configuration properties and examples
Property Type Required Default Description
builtins string Yes — Comma-separated list of OPC-UA BuiltInType names to match (e.g. Int32 or Float,Double). Names are case-sensitive and must match the OPC-UA BuiltInType enumeration; unrecognized names are discarded with a warning, so if no valid name remains no record matches.
field.name string No `` Name of the KNetOPCAlarmEvent field whose value type is checked. Must be set when the predicate is applied to KNetOPCAlarmEvent records; it is not used with MonitoredItemNotification records.

Examples

Keep only the records whose node value is an Int32:

predicates=IsInt32
predicates.IsInt32.type=org.mases.knetopc.transformations.predicates.KNetOPCPredicateBuiltIn
predicates.IsInt32.builtins=Int32

transforms=KeepInt32
transforms.KeepInt32.type=org.apache.kafka.connect.transforms.Filter
transforms.KeepInt32.predicate=IsInt32
transforms.KeepInt32.negate=true

Keep only the records whose node value is a floating point number (Float or Double):

predicates=IsFloating
predicates.IsFloating.type=org.mases.knetopc.transformations.predicates.KNetOPCPredicateBuiltIn
predicates.IsFloating.builtins=Float,Double

transforms=KeepFloating
transforms.KeepFloating.type=org.apache.kafka.connect.transforms.Filter
transforms.KeepFloating.predicate=IsFloating
transforms.KeepFloating.negate=true

Keep only the KNetOPCAlarmEvent records whose Severity field is a UInt16:

predicates=IsSeverityUInt16
predicates.IsSeverityUInt16.type=org.mases.knetopc.transformations.predicates.KNetOPCPredicateBuiltIn
predicates.IsSeverityUInt16.builtins=UInt16
predicates.IsSeverityUInt16.field.name=Severity

transforms=KeepSeverityUInt16
transforms.KeepSeverityUInt16.type=org.apache.kafka.connect.transforms.Filter
transforms.KeepSeverityUInt16.predicate=IsSeverityUInt16
transforms.KeepSeverityUInt16.negate=true

KNetOPCPredicateNotOldThan

Java class: org.mases.knetopc.transformations.predicates.KNetOPCPredicateNotOldThan

Matches a record only if the elapsed time between the record timestamp and the current time is less than the configured delta.time.in.seconds. The timestamp used is controlled by the UseServerTimestamp property of the connector configuration (see KNetOPC Source configuration): when true the ServerTimestamp is used, otherwise the SourceTimestamp is used.

Setting delta.time.in.seconds to -1 disables the check and all records match regardless of their age.

Note

With the Binary encoding type this predicate evaluates the record through views directly over the JVM memory, on both .NET 8 and .NET 10; see Performance and runtime requirements.

Configuration properties and example
Property Type Required Default Description
delta.time.in.seconds integer Yes — Maximum age of a record in seconds. Records older than this value do not match. Set to -1 to disable the check and let all records match.

Example

Discard the records older than 30 seconds: Filter drops the records for which the predicate is false, i.e. the older ones:

predicates=IsFresh
predicates.IsFresh.type=org.mases.knetopc.transformations.predicates.KNetOPCPredicateNotOldThan
predicates.IsFresh.delta.time.in.seconds=30

transforms=DropOld
transforms.DropOld.type=org.apache.kafka.connect.transforms.Filter
transforms.DropOld.predicate=IsFresh
transforms.DropOld.negate=true

KNetOPCPredicateValueCompare

Java class: org.mases.knetopc.transformations.predicates.KNetOPCPredicateValueCompare

Matches a record only if the OPC-UA node value satisfies a comparison condition against a configured threshold. The predicate works on scalar values only; records with array or non-scalar values do not match and an error is logged. The OPC-UA BuiltInType of the incoming value must match the builtin configuration property exactly, otherwise the record does not match and an error is logged.

Note

This predicate takes full advantage of JCOBridge HPA with .NET 10 and the Binary encoding type; see Performance and runtime requirements.

Supported types, configuration properties and examples

Supported types

builtin value OPC-UA BuiltInType .NET type Supported operators
4 Int16 short greater, lower, equal
5 UInt16 short greater, lower, equal
6 Int32 int greater, lower, equal
7 UInt32 int greater, lower, equal
8 Int64 long greater, lower, equal
9 UInt64 long greater, lower, equal
10 Float double greater, lower, equal
11 Double double greater, lower, equal
12 String string greater, lower, equal, start.with, end.with, contains
Note

For Float and Double types, equality is evaluated with a tolerance of 1E-06. For String type, greater and lower use lexicographic ordering (string.Compare).

Configuration properties

At least one operator flag must be set to true. For numeric types, exactly one of greater, lower, or equal must be true. For String type, one of greater, lower, equal, start.with, end.with, or contains must be true.

Property Type Required Default Description
builtin integer Yes — The OPC-UA BuiltInType integer value of the node to compare. See the supported types table above. If not set the incoming BuiltInType of the message is used.
field.name string No `` If set, the data within a KNetOPCAlarmEvent and associated to the field name is used for the comparison
greater boolean No false If true, matches records where the value is greater than the configured threshold.
lower boolean No false If true, matches records where the value is lower than the configured threshold.
equal boolean No false If true, matches records where the value is equal to the configured threshold.
start.with boolean No false (String only) If true, matches records where the string value starts with the configured threshold.
end.with boolean No false (String only) If true, matches records where the string value ends with the configured threshold.
contains boolean No false (String only) If true, matches records where the string value contains the configured threshold.
short short Conditional — Threshold value used when builtin is 4 (Int16).
ushort unsigned short Conditional — Threshold value used when builtin is 5 (UInt16).
int integer Conditional — Threshold value used when builtin is 6 (Int32).
uint unsigned integer Conditional — Threshold value used when builtin is 7 (UInt32).
long long Conditional — Threshold value used when builtin is 8 (Int64).
ulong unsigned long Conditional — Threshold value used when builtin is 9 (UInt64).
double double Conditional — Threshold value used when builtin is 10 (Float) or 11 (Double).
string string Conditional — Threshold value used when builtin is 12 (String).

Examples

Keep only the records where an Int32 node value is greater than 100:

predicates=IsAbove100
predicates.IsAbove100.type=org.mases.knetopc.transformations.predicates.KNetOPCPredicateValueCompare
predicates.IsAbove100.builtin=6
predicates.IsAbove100.greater=true
predicates.IsAbove100.int=100

transforms=KeepAbove100
transforms.KeepAbove100.type=org.apache.kafka.connect.transforms.Filter
transforms.KeepAbove100.predicate=IsAbove100
transforms.KeepAbove100.negate=true

Keep only the records where a String node value contains "alarm":

predicates=IsAlarm
predicates.IsAlarm.type=org.mases.knetopc.transformations.predicates.KNetOPCPredicateValueCompare
predicates.IsAlarm.builtin=12
predicates.IsAlarm.contains=true
predicates.IsAlarm.string=alarm

transforms=KeepAlarm
transforms.KeepAlarm.type=org.apache.kafka.connect.transforms.Filter
transforms.KeepAlarm.predicate=IsAlarm
transforms.KeepAlarm.negate=true

KNetOPCTransformationEncodingTypeChange

Java class: org.mases.knetopc.transformations.KNetOPCTransformationEncodingTypeChange

Converts each record to the OPC-UA encoding type set in encoding.type.value (Binary, Xml or Json). Its main purpose is to let the Source connector emit the records in Binary encoding, the best option for performance, and still write the records of a topic in Xml or Json, which are simple to read.

The transformation behaves as follows:

  • If the record is already encoded with the configured encoding type, it is returned untouched.
  • Otherwise the record is decoded and encoded again with the configured encoding type; Xml and Json are written as UTF-8 text.
  • The new record keeps topic, partition, key and timestamp. Its value is a byte array and the encoding type header of the record is updated, so consumers can read the right encoding.
  • If the conversion fails, the error is logged and the exception is propagated to Kafka Connect, which handles it according to its error-handling configuration.

A typical pipeline is:

Source connector (Binary encoding)
    └─► Standard Kafka Connect transformations with their predicates evaluated on the Binary records
        (e.g. splitting the records into two topics, full benefit of HPA)
            └─► KNetOPCTransformationEncodingTypeChange (Xml or Json) on the records to be read directly

Keeping the Binary encoding type in the Source connector (EncodingType set to 0 in the KafkaConnectParameters, see KNetOPC Source configuration; the default is 2, Json) lets predicates take advantage of HPA, as described in Performance and runtime requirements. As in any Kafka Connect pipeline, transformations are applied in the order in which they are listed in transforms, and a predicate is evaluated on the record as it is when the transformation it is attached to runs: place KNetOPCTransformationEncodingTypeChange after the transformations whose predicates should work on Binary records.

The value of the new record is a byte array (Xml and Json are written as UTF-8 text), so the Source connector must use the ByteArrayConverter as value converter, as it already does with the Binary variant of the connector properties file (see Connectors).

Configuration properties and examples

In addition to the common base properties (application.name, application.version, always.use.full.decoder):

Property Type Required Default Description
encoding.type.value string No Binary The destination encoding type. Allowed values are Binary, Xml and Json (case-sensitive); any other value is a configuration error.

Examples

Convert all records to JSON:

transforms=ToJson
transforms.ToJson.type=org.mases.knetopc.transformations.KNetOPCTransformationEncodingTypeChange
transforms.ToJson.encoding.type.value=Json

Convert all records to XML:

transforms=ToXml
transforms.ToXml.type=org.mases.knetopc.transformations.KNetOPCTransformationEncodingTypeChange
transforms.ToXml.encoding.type.value=Xml

Split the records by age: records older than 60 seconds are routed to a dedicated topic and converted to JSON, while the other ones are published on the original topic without changing the encoding type (the Source connector is configured with EncodingType set to 0, Binary):

predicates=NotOld
predicates.NotOld.type=org.mases.knetopc.transformations.predicates.KNetOPCPredicateNotOldThan
predicates.NotOld.delta.time.in.seconds=60

transforms=RouteOld,OldToJson

# Records older than 60 seconds (negated predicate) are routed to a dedicated topic...
transforms.RouteOld.type=org.apache.kafka.connect.transforms.RegexRouter
transforms.RouteOld.regex=(.*)
transforms.RouteOld.replacement=$1.old
transforms.RouteOld.predicate=NotOld
transforms.RouteOld.negate=true

# ...and converted to JSON
transforms.OldToJson.type=org.mases.knetopc.transformations.KNetOPCTransformationEncodingTypeChange
transforms.OldToJson.encoding.type.value=Json
transforms.OldToJson.predicate=NotOld
transforms.OldToJson.negate=true

The timestamp evaluated by KNetOPCPredicateNotOldThan is the ServerTimestamp when UseServerTimestamp is true in the KafkaConnectParameters (see KNetOPC Source configuration), otherwise the SourceTimestamp.