Klevr Product Documentation logo

Routing Source Stage

The Routing Source stage allows JSON messages to be routed based on the payload contents or on file metadata from an earlier inbound stage.

Stage Overview

The Routing Source stage allows JSON-formatted messages to be routed based on either:

  • The JSON payload contents passed to the stage; or
  • File metadata present in the event message from a file-based inbound stage that has been run earlier in the overall integration.

Stage Definition File Location

All Routing Source stages are defined by creating an appropriately formatted JSON definition file in the following location:

interfaces
{businessUnitCode}
{domainCode}
{integrationName}
rt
sc
{STAGE_NAME}.json

Payload-Based Routing

Stage JSON Definition File Format

The JSON definition file for a Routing Source stage for payload-based routing (where routing is performed on the basis of a supplied JSON payload message) is as follows:

{
  "name": "stage-name",
  "displayName": "Brief Stage Title",
  "description": "Brief description of the stage.",
  "enabled": "$env:STATUS_<INTEGRATION_NAME>",
  "source": "source-event",
  "concurrency": 10,
  "schemaFilename": "schemas/path/to/schema.json",
  "routeField": "['field']",
  "routeOptions": [
    {
        "condition": "condition1",
        "name": "rt-sc-stage-name-condition1"
    },
    {
        "matchType": "string",
        "condition": "condition2",
        "name": "rt-sc-stage-name-condition2"
    },
    {
        "matchType": "regex",
        "condition": "condition3_.*",
        "name": "rt-sc-stage-name-condition3"
    }
  ],
  "silenceUnknownRouteErrors": true,
  "preLogTransformSchemaFileName": "schemas/path/to/schema/schema-name.liquid",
  "preLogTransformSchemaType": "liquid|javascript",
  "preLogTransformFormat": "json|xml|csv"
}
PropertyDescription
nameThe name of the stage.
displayNameOptional (but highly recommended). A short (3 or 4 word) "display name" for the stage, used as a "title" of the stage in the Integration Hub Portal service's self-documentation capability.
descriptionOptional (but highly recommended). A brief (10 to 15 word) description of the stage, used as a brief description of the stage's purpose in the Integration Hub Portal service's self-documentation capability. For a more detailed explanation (when needed), use the stage markdown feature.
enabledOptional boolean flag (true or false). Default is true.

Generally set via a DevOps variable. Controls if the stage is deployed enabled or not.
sourceThe source event that the stage subscribes to. See Pub/Sub Model.

Alternatively, sources may be supplied, and an array of one or more source events can be subscribed to.
concurrencyOptional number of concurrent runs permitted for the stage. Default is 10.
schemaFilenameA filename that defines the JSON schema for the incoming payload. It is recommended that this be shared with the Inbound API stage JSON schema, if relevant.
routeFieldThe top-level object in the JSON payload to inspect for routing. NOTE: Watch the formatting of this field. Must be in square brackets and single quotes, as per example above.
routeOptionsAn array of routing objects. See the Routing Process details below.
silenceUnknownRouteErrorsOptional boolean flag (true or false). Default is false. When true, the stage will silently do nothing if the routeField does not have a matching route. The default behaviour is that messages that are processed that do not match any routing condition cause the Logic App workflow to terminate with a failure.

Pre-Logging Transformation

This stage supports the optional pre-logging transformation feature using the following fields:

  • preLogTransformSchemaFileName
  • preLogTransformSchemaType
  • preLogTransformFormat

See the Pre-Logging Transformation for details.

Routing Process

The stage only supports inspecting JSON payloads, and only supports inspecting a top-level property of the payload.

As a result, a JSON payload that is an array at the top level cannot be routed.

Similarly, a JSON payload of the following format:

{
  "key1": "string1",
  "key2": [
    {
      "key3": "string3"
    }
  ]
}

can only be routed on the key1 value.

The property that will be inspected for routing is defined by the routeField field.

The value of the property will be compared against the condition values in the routeOptions array.

By default, the comparison of the property against the condition will be a string-based "contains" operation - that is, the stage inspects if the property contains the condition value.

Alternatively, the comparison method can be defined by setting an optional matchType value:

  • If set to string, then the default string-based "contains" comparison is performed; otherwise
  • If set to regex, then a regular expression comparison is performed.

When a match is found, the stage will emit an event that matches the corresponding name value of the matching routeOptions array object. Other stages can then subscribe to the events emitted, to allow different messages to be routed and processed differently.

It is recommended that the rt-sc-stage-name-condition format for emitted events be adhered to.

Non-Standard Routing

  • If a non-JSON payload needs to be routed, use a Transform Liquid stage to first transform the payload into JSON, then route the payload, then transform the payload back into something other than JSON (if required).
  • If a JSON payload needs to be routed on a property that is not a top-level value, transform the payload to include the required value at the top level, then route the payload.
  • If a JSON payload needs to be routed on multiple properties, transform the payload to concatenate the properties into a new, single top-level property, then route the payload.

File Metadata-Based Routing

Stage JSON Definition File Format

The JSON definition file for a Routing Source stage for file metadata-based routing (where routing is performed on the basis of file metadata present in the event message from a file-based inbound stage that has been run earlier in the integration) is as follows:

{
  "name": "stage-name",
  "enabled": "$env:STATUS_<INTEGRATION_NAME>",
  "source": "source-event",
  "concurrency": 10,
  "routeOnEventDataInterface": "in-sftp-stage-name",
  "routeOnEventDataField": "name|path|size|lastModified",
  "routeOptions": [
    {
        "condition": "condition1",
        "name": "rt-sc-stage-name-condition1"
    },
    {
        "matchType": "string",
        "condition": "condition2",
        "name": "rt-sc-stage-name-condition2"
    },
    {
        "matchType": "regex",
        "condition": "condition3_.*",
        "name": "rt-sc-stage-name-condition3"
    }
  ],
  "silenceUnknownRouteErrors": true
}
PropertyDescription
nameThe name of the stage.
enabledOptional boolean flag (true or false). Default is true.

Generally set via a DevOps variable. Controls if the stage is deployed enabled or not.
sourceThe source event that the stage subscribes to. See Pub/Sub Model.

Alternatively, sources may be supplied, and an array of one or more source events can be subscribed to.
concurrencyOptional number of concurrent runs permitted for the stage workflow. Default is 10.
routeOnEventDataInterfaceThe full name of the file-based inbound stage that previously ran, on which file metadata routing should be run.
routeOnEventDataFieldThe name of the file metadata to use for the routing decision. One of name (file name), path, size, or lastModified.
routeOptionsAn array of routing objects. See the Routing Process details below.
silenceUnknownRouteErrorsOptional boolean flag (true or false). Default is false. When true, the stage will silently do nothing if the routeField does not have a matching route. The default behaviour is that messages that are processed that do not match any routing condition cause the Logic App workflow to terminate with a failure.

Routing Process

The stage only supports routing based on the name, path, size, or lastModified file metadata values. This is controlled by setting the routeOnEventDataInterface and routeOnEventDataField values, which uniquely define both a previous stage (which must be a file-based Inbound Stage that sets file metadata properties), and the file metadata field to route on.

The file metadata value selected will be compared against the condition values in the routeOptions array.

By default, the comparison of the property against the condition will be a string-based "contains" operation - that is, the stage inspects if the property contains the condition value.

Alternatively, the comparison method can be defined by setting an optional matchType value:

  • If set to string, then the default string-based "contains" comparison is performed; otherwise
  • If set to regex, then a regular expression comparison is performed.

When a match is found, the stage will emit an event that matches the corresponding name value of the matching routeOptions array object. Other stages can then subscribe to the events emitted, to allow different messages to be routed and processed differently.

It is recommended that the rt-sc-stage-name-condition format for emitted events be adhered to.

Last updated on