Business logic and actions in a ThingWorx application are driven by events. Events are interesting or critical property states that a Thing publishes to subscribers. Events are defined at the thing, thing template, or thing shape level, and can be as simple as a new data value from a device, to complex events from many data points. An event that is created on a thing shape or thing template level is inherited down into the entities that implement the shape or template that defines the event.
Types of Events
Every entity in ThingWorx can use several built-in events. These events are automatically triggered when a prerequisite condition is met. In some cases, you must provide information that determines the specifics of that prerequisite.
Common built-in events include:
In ThingWorx, there are standard events and related data packets (defined by Data Shapes). The most common type of event is a Data Change related to a Thing property. The Data Change fires when a property value changes. The specifics of this event can be configured from the Data Change Info section of the Property Creation page. When you define a property, there are many configuration aspects.
Using DataChangeEvent, you have a few options for setting an event to fire when there is new data for a property:
only if the data has changed
only if the data evaluates true or false
only if the new value changed beyond a defined threshold
The Alert event is also attached to a property and is set up from the Property Definition page. An Alert event fires when the value of the property reaches a certain threshold or value. Depending on the base type, you may specify the condition of this event from the Manage Alerts button.
Timer events can be used to run jobs or fire events on a regular basis. Things themselves can fire specific events such as Thing Start or “special” things, like a Timer type thing that contains special event(s).
In ThingWorx Composer, open up the Thing, Thing Template, or Thing Shape for edit where the new Event will be added
From the sidebar menu under Entity Information, select Events
Click Add My Event
Provide the event with a name and a data shape that describes the data being sent to a subscriber
Click Done and Save
Once created, the event appears on the Subscriptions page for subscribing. Since the event is custom built, you must specify when it triggers. This is often accomplished from within a service.
There should be a subscriber to the event in the model. The subscriber is sent a data packet and the subscription is initiated. If no one is subscribed to the event (no one is listening), nothing happens.
DataChange events hit the event processing subsystem (see Event Processing Subsystem below), which has fewer threads allocated to it than some other subsystems:
If queries within subscriptions to data change events take too long, this will cause a back-up in the event processing subsystem
Too much activity in this subsystem may result in poor system performance, and even server crashes
Be cautious what types of calculations are performed in data change event subscriptions