The Classifier codec connectivity plug-in
The Classifier codec can be used to take messages from a transport and assign them message types suitable for the host. Typically this is the type of an EPL event, which corresponds to the metadata field
sag.type (see also
Metadata values) when you are using the
apama.eventMap host plug-in. The classifier can inspect the message payload and metadata in order to classify messages to the correct type. If it finds a match, it sets the
sag.type appropriately, overwriting anything which was there before.
The source code for this plug-in is also shipped as a sample in the samples/connectivity_plugin/cpp/classifier directory of your Apama installation.
To reference the Classifier codec, an entry such as the following is required in the
connectivityPlugins section of the configuration file (see also
Configuration file for connectivity plug-ins):
classifierCodec:
libraryName: ClassifierCodec
class: ClassifierCodec
You then need to add classifierCodec into your connectivity chains with the configuration for that instance. An example configuration may look as follows:
classifierCodec:
rules:
- SomeType:
- payload.someField: someValue
- payload.anotherField:
- AnotherType:
- metadata.metadataField: true
- FallbackType:
The top-level configuration element is just rules. It contains a list of one or more types which can be assigned to messages. Each type contains a list of rules to match against the type with the following properties:
Types are evaluated in order and the first one to match is assigned to a message.
If the list of rules for a type is empty, then it matches any message. There should be only one such type and it must be last. With
FallbackType in the above example configuration, it is always guaranteed that a type is set on a message (because
FallbackType is a last resort).
Rules within a type are evaluated in order, and comparisons stop on the first failure so that common cases are evaluated first.
Rules within a type give the name of a field as the key and either a string value or empty as the value.
Field names must start with "metadata." or "payload.".
Metadata and payload field names which contain a period (.) refer to nested map structures within the metadata or payload. For example,
metadata.http.headers.accept refers to a map called "http" within the metadata, which contains a map called "headers", which contains an element called "accept".
Empty rules match if the field is present (even if empty) with any value. With
SomeType in the above example configuration, this rule matches if
anotherField in the payload contains
any value.
All rules within a type must be true to match that type. For the above example configuration, this means that if
anotherField in the payload exists, but
someField does not contain
someValue, then
SomeType does not match.
If no types match, then the
sag.type metadata field remains unchanged.
For "payload." rules to match, the payload must be a
java.util.Map (Java) or
map_t (C++) with string keys.
Messages coming
from the direction of the host do not interact with the Classifier codec at all. Use the
apama.eventMap host plug-in, which always sets a
sag.type for messages going from the host towards the transport.
If you want to encode an or rule, then you can list the same type twice with different sets of rules.