Variable
Description
A Variable component is used to declare a new variable.
As the data record moves through the scenario, it can be extended with additional information. This additional information is stored in variables - named placeholders that are attached to the data record during scenario execution. Variables make it possible to retain and reuse intermediate results or derived data later in the scenario.
The SpEL expression defining the value of the variable must evaluate to one of the SpEL data types.
Examples
Let's assume that:
- the name of the scenario which is being authored is
example-scenario. - the processing mode is streaming
- events in the in the Kafka topic ingested by the scenario contain just one field
name(type string) - as in the example scenario created when to sign up to Nussknacker Cloud. - the last event payload is "John"
| Expression | Value |
|---|---|
#meta.processName | "example-scenario" |
#meta.processName.length | 16 |
#meta.processName +" " + #input.name | "example-scenario John" |
#input.name.length > 4 | FALSE |
You can find many more examples of SpEL expression in the SpEL cheetsheet.
RecordVariable
The specialized record-variable component can be used to declare SpEL records. The same outcome can be achieved using a plain Variable component, just make sure to write a valid SpEL expression which evaluates to a record.
Internally, Nussknacker converts SpEL record into a JSON object. In simple cases, the SpEL expression which evaluates to a SpEL record is identical to JSON. Example:
{ "name": "John", "surname": "Doe"}