To detect duplicate messages, it is important to place the Checkpoint activity before any activities that we do not want to execute more than once.
We must specify a value for the duplicateKey element in the Checkpoint activity input schema.
This value should be some unique key contained in the event data that starts the process.
How it works ?
For example, the TransactionID value is unique for all new orders.
The following describes the procedure for duplicate detection by the process engine:
1. An incoming message is received and a process instance is created.
2. Activities in the process instance are executed until the first Checkpoint activity is reached. The Checkpoint activity has a value specified for the duplicateKey input element.
3. The process engine checks the current list of duplicateKey values for a matching value.
a. If no process instance has stored the given duplicateKey value, the process engine stores the value and completes the Checkpoint activity.
b. If another process instance has already stored the given duplicateKey value, then process engine terminates the process and throws a DuplicateException.
Process Engine Properties for Duplicate Detection
The following process engine properties need to set in bin/bwengine.xml to control duplicate key detection.
• bw.engine.dupKey.enabled —
specifies whether duplicate detection is performed.
true (the default) - indicates the process engine will check for identical duplicateKey values.
false -indicates duplicateKeys when specified are ignored.
• bw.engine.dupKey.timeout.minutes —
specifies how long (in minutes) to keep stored duplicateKey values.
The default is 30 minutes.
Value -1 indicates the duplicateKey values are deleted when the job completes.
Value 0 indicates to store duplicateKey values indefinitely.
Any positive integer greater than 0 indicates the number of minutes to keep stored duplicateKeys.
• bw.engine.dupKey.pollPeriod.minutes —
specifies the number of minutes to wait before polling for expired duplicateKey values.