IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Developing monitor models > Create monitor models > Defining monitor details models > Defining inbound events

Handling duplicate events

Sometimes monitor models receive duplicate events.

For example, if a client application that is sending events to the monitor model through the REST event emitter does not receive its expected response from the emitter, it might decide to send the event a second time. Depending on the effects of an incoming event, the monitor model might need a way to recognize and handle a duplicate arrival. If the event only sets metrics by copying some of its content, setting the metrics twice will cause no harm. However, if counters are incremented or outbound events are triggered by the event, duplicate deliveries are undesirable.

One possible approach to block duplicate events is to use a string metric to retain the unique event identifiers of the events that have already been received. This approach will work with any unique event identifier in your events.

To handle duplicate events:


Procedure

  1. Create a string metric with a name like eventsSeen.

  2. Add a metric value expression similar to the following:
    eventsSeen <- fn:substring( fn:concat( event/predefinedData/globalInstanceId, ' ', eventsSeen ), 1, 4000 )
    The fn:concat() function adds the incoming identifier, in this case globalInstanceID, to the eventsSeen string, separated by a blank. The fn:substring() function is used only to restrict the maximum length of the string, in this case to 4000 characters. You can omit this function if you know that this limit will not be reached. New event identifiers are added at the beginning of the string, so that if the fn:substring() function ever cuts off identifiers, they will be from events that arrived long ago and are unlikely to have duplicate arrivals. Because the metric value expression refers to an inbound event, the expression is evaluated each time that the inbound event arrives and the string is updated with the new identifier.

  3. Use a Boolean expression similar to the following to test whether the event identifier has already been seen:
    fn:contains( eventsSeen, fn:concat( event/predefinedData/globalInstanceId, ' ') )
    The eventsSeen metric is treated as a list of strings. You can use the Boolean expression in a trigger condition to prevent it from firing if the incoming event is a duplicate, or in a metric value expression to prevent the expression from running twice. You would encode the metric value expression as follows:
    myMetric <- if ( fn:contains( ......... ) ) then myMetric else  <new_value>

Defining inbound events for monitoring contexts