Developer ‘Tiqs & Tricks: Transformations

Developer ‘Tiqs & Tricks

November 2023

Transformations

 

The App Activity Patterns within Service Event Handlers (both Visual and Internal) all have an important event-processing purpose, and Vantiq adds more almost every release.  This month, let’s take a closer look at the Transformation Activity Pattern and explore some of the many ways developers can get the most from it.

 

The Basics:  The Transformation Activity Pattern allows developers to change the structure of the event message flowing through the App.  Developers can choose to accomplish their event transformations in one of three ways:

The three ways to make a transformation

·      Transformation Procedure: This is a VAIL procedure (either within the Service or not) that takes in the event as a parameter and returns the new event.

·      Visual Transformation: If the schema type is known, the system provides a list of incoming event properties, allowing the developer to do something with them.

·      Projection: This is basically meant to be a one-line VAIL expression that makes a change with all or part of the event, sending that payload on as the new event.

 

Top Five Examples of Transformation Uses:  The preliminaries out of the way, let’s see Transformation in action.

Example #1: Add or Remove Event Properties

Working directly with the event message properties is a good case for using the Visual Transformation.  Here we are in a Visual Transformation configuration after two enriched sensor streams have been joined into one.  Notice the redundancy?

After making gratuitous use of the “trash” icon, we’ve culled the event properties to what we actually want:

And by clicking on the plus sign next to “Add a Transformation,” we can add event properties too:

 

Example #2: Merge Event Properties

In this example, we’re formatting a few of the String value event properties into a full string to make a single street address property:

 

Example #3: Add Procedure Call Results to Events

Here, let’s make a quickie timestamp by adding an event property in the Transformation and setting it equal to the return value of the Vantiq built-in now() procedure.  There, done:

 

Example #4: Alter Event Properties

Really, anything can be done to the existing event properties.  Besides giving them static values, developers can mathematically manipulate numerical type properties, like double the values as they pass through the Transformation:

And here’s a Transformation Projection configuration; a single ternary operation that replaces the whole event with a single word.  If the PumpId is “Pump1,” that word is “PumpUno.”  Otherwise, it’s “PumpOther.”

 

Example #5: Produce New Events

Within Transformation procedures, developers can perform all of the actions we’ve seen from the Visual and Projection options, and more.  In this Procedure example, we’re taking a portion of an event and publishing it to another Service to be processed asynchronously from the current Service:

No doubt you’re thinking that a Procedure Activity Pattern or VAIL Block (with no return statement) could accomplish the same actions, and you’d be right.  There’s a lot of flexibility in Vantiq development.  In Transformation procedures, what is returned is automatically the downstream event.

And yes, you could split the event stream with another Visual Transformation, cull the event down to just the count, then drag in a PublishToService task to do this too!  A procedure like this one could be used to send to several other Services at once, thereby making the App flow a little less “messy.” Compare the flow above to this:

Conclusion:  It’s hard not to think of Transformation Activity Patterns as a “Swiss Army Knife” of functionality.  Transformations can:

·      Remove or add event properties

·      Change the event’s JSON structure depth

·      Build API inputs, Generative AI prompts, compound event properties…

·      Execute procedures and make the results part of the downstream event

·      “Shortcut” event flow tasks, like publishing to multiple services at once

This list could go on, but you get the picture.  Transformation Activity Patterns give developers the control they need over their events and event flows, in order to build truly effective real-time applications.

Posted: December 1, 2023 at 10:30 pm
Replies: 0
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
© Vantiq 2024 All rights reserved  •  Vantiq Corporation’s Privacy Policy and Cookie Policy