Change Detection
In this microlearning, we will introduce the relevant stateful components to configure the Change Detection operation in the context of State Generation. In case you want to learn the basics of the State Generation functionality, please check out eMagiz State Generation.
Should you have any questions, please get in touch with academy@emagiz.com.
1. Prerequisites
- Basic knowledge of the eMagiz platform
- Basic knowledge of the eMagiz State Generation
2. Key concepts
In this microlearning, we will introduce the relevant stateful components to configure the Change Detection operation in the context of State Generation functionality.
- By Change Detection, we mean: a form of operation in which we identify and monitor changes in the message flow over time in such a way that it allows us to take action based on the detected changes. These changes are events that occur at specific points in time that represent deviations from past states. And so, when a particular change event is detected, a corresponding action can be executed.
There are some check points to think about beforehand when setting up the Change Detection operation:
- What is the incoming message that will be monitored?
- What is the condition for the change detection?
- What is the action that can be executed when the change is detected?
- How to store the past events as states, and for how long these states will be stored?
- How to use the states to detect change event?
- How to set an action when the detection is triggered?
3. Setting up Change Detection operation
In general, to configure the Change Detection operation, you first need to set up the storage to persist the states and then afterwards set up the component to detect the change as well as the action when the change is detected.
3.1 Storage Mechanism for State Persistance
As mentioned above, first, we need to think about how to configure the storage in the platform to persist the states as well as how to store the states into this storage. The idea here is so that these states later on can be retrieved from somewhere else in your integration landscape to detect changes in incoming messages by comparing them to past states. For such a purpose, eMagiz provides two support objects to set up this storage mechanism and one flow component to store the states into it:
- Infinispan cache manager
- Infinispan metadata store
- Metadata outbound channel adapter
Please refer to this State Persistence microlearning to learn on how to configure these support objects and flow component.
3.2 Stateful Configuration to Detect Changes
Once you have configured the storage mechanism, now you can start with setting up the component to retrieve the past states to detect changes in incoming messages by comparing them to past states. In principle, you can retrieve the past state data with any flow components that support SpEL expression (e.g., Standard transformer, Standard filter, etc.) and there is no specific component that is tightly coupled with Change Detection - State Generation. That means this operation relies mainly on the retrieval of the past state data and its comparison to the incoming message by means of SpEL expression, and evaluate if there is deviations that you deem necessary to take action. Some examples as follow:
The example above demonstrates how to use a Standard filter to detect significant temperature changes in sensor readings from specific locations. The SpEL expression evaluates whether the difference between the current and previous temperatures from the same sensor location is too extreme, in this case, checks if the difference exceeds 30 degrees. If this is the case, then sends the sensor reading to the alert flow.
Another example is to use a Standard header enricher. As shown above, we instantiate a header called temperatureDifference that contains the difference between the incoming temperature reading and the previous reading. By having this value specified in the header, you can use this value to evaluate whether this message should be treated as an alert by routing it to another flow or not as well as to compose a new payload as an alerting message that mentions the temperature difference as shown below, and so on.
4. Key takeaways
- With State Generation, you can compare incoming messages to past state data to detect any changes that may trigger specific actions.
- To set up a State Generation - Change Detection operation, you need to configure a metadata storage and a flow component that supports SpEL expression to perform the detection.
- To minimize the hurdles and speed up the process of setting up a State Generation - Change Detection operation, we recommend using a store item that is available here.
5. Suggested additional readings
If you are interested in this topic and want more information on it, please read the help text provided by eMagiz and read the following microlearning on the related topic: