Skip to main content

Transformer

Transformers are independent unit of proccessing that comprise of the logic that an XMessage flows through. The Orchestrator may chain together one or more transformers, by defining a logic definition, and converting it into a state machine. Transformers may also modify the current state of the machine.

Transformers can correspond to one of the following classes:

Learn more about all the supported transformer types here.

GenericTransformer

A GenericTransformer is a class of transformers that do any kind of processing on an XMessage. The transformer may or may not modify the XMessage during the processing of an XMessage.

These types of transformers have only two output states:

  • When transformer sucessfully completes (onSuccess) (By default this is set to global 'done' state)
  • When transformer processing errors out (onError) (By default this is set to global 'error' state)

Learn more about how to create a new GenericTransformer here.

Here's how you create a GenericTransformerNode for a logic definition:

{
"id": "someUniqueId",
"type": "TRANSFORMER_TYPE",
"config": {
// Config is different based on the exact type of transformer you use
},
"states": {
"onSuccess": "targetId",
"onError": "targetId"
}
}

IfElseTransformer

An IfElseTransformer is a class of transformer that produces a binary state 'if' or 'else' and optionally modifies XMessage data.

These types of transformers have two output states:

  • If (if)
  • Else (else) (This is also the default state in case of error)

Learn more about how to create a new IfElseTransformers here.

Here's how you create a IfElseTransformer for a logic definition:

{
"id": "someUniqueId",
"type": "TRANSFORMER_TYPE",
"config": {
// Config is different based on the exact type of transformer you use
},
"states": {
"if": "targetId",
"else": "targetId"
}
}

RetryTransformer

A RetryTransformer is a class of transformer that can be attached to the error state of any other transformer to retry the functionality of a transformer in case of failure.

These types of transformers have two output states:

  • Retry a failed transformer process (retry)
  • Error out when all retires are exusted (error)

Learn more about how to create a new RetryTransformer here.

Here's how you create a RetryTransformer for a logic definition:

{
"id": "someUniqueId",
"type": "TRANSFORMER_TYPE",
"config": {
// Config is different based on the exact type of transformer you use
},
"states": {
"retry": "5",
"error": "targetId"
}
}

SwitchCaseTransformer

A SwitchCaseTransformer is a class of transformer that produces arbitary number of output states. It activates one of the target states based on which state a transformer generates. A SwitchCaseTransformer may optionally modify XMessage data as well.

Learn more about how to create a new SwitchCaseTransformer here.

Here's how you create a SwitchCaseTransformer for a logic definition:

{
"id": "someUniqueId",
"type": "TRANSFORMER_TYPE",
"config": {
// Config is different based on the exact type of transformer you use
},
"states": {
"state1": "targetId1",
"state2": "targetId2",
...
}
}

Example

Here is a complete example of a logic definition which illustrates how you would chain different transformers together.

{
"logicDef": {
"id": "myTestMachine",
"transformers": [
{
"id": "1",
"type": "HTTP_GET",
"config": {
"url": "https://cat-fact.herokuapp.com/facts/"
},
"states": {
"onSuccess": "2"
}
},
{
"id": "2",
"type": "HTTP_GET",
"config": {
"url": "https://cat-fact.herokuapp.com/facts/"
},
"states": {
"onSuccess": "3"
}
},
{
"id": "3",
"type": "RANDOM_BINARY",
"states": {
"if": "2",
"else": "4"
}
},
{
"id": "4",
"type": "RANDOM_BINARY",
"states": {
"if": "3",
"else": "5"
}
},
{
"id": "5",
"type": "LABEL_CLASSIFIER",
"config": {
"url": "my_endpoint",
"prompt": "paddy and crops",
"existingLabel": "LABEL_0",
"supersedeThreshold": "0.8",
"suppressedLabels": ["LABEL_2"],
"suppressionThreshold": 0.95,
"persistLabel": true,
"minimumThreshold": 0.6,
},
"states": {
"LABEL_0": "7",
"LABEL_1": "7",
"LABEL_2": "7",
"LABEL_3": "7",
"LABEL_4": "7",
"LABEL_5": "7",
"LABEL_6": "7",
"default": "6"
}
},
{
"id": "6",
"type": "SIMPLE_RETRY",
"config": {
"retries": 5,
"delay": 5000
},
"states": {
"retry": "5",
"error": "error"
}
},
{
"id": "7",
"type": "HTTP_GET",
"config": {
"url": "https://cat-fact.herokuapp.com/facts/"
}
}
]
},
"message": {
"mockMessage": "val"
}
}