Service validators and redelivery
objectiser Feb 14, 2009 6:34 AMThe current Service Validator mechanism uses a global filter to observe messages being passed between ESB service descriptors. If the endpoint associated with the message has a Service Validator configured, then the Service Validator is used to determine if that message is appropriate in the context of the business transaction (i.e. is it a known message type, is it being sent/received in the correct order, etc).
The problem is that once the service validator has indicated that the message is valid, and the filter passes the message on for delivery to its destination service descriptor, the message is considered to have been processed.
However if while processing the message, the destination service descriptor has a problem that results in an exception being thrown, the ESB will automatically enter a retry cycle (unless this is turned off). Each time the message is redelivered, the Service Validator would now consider it to be invalid, as it has already received such a message and flagged it as ok - therefore the service validator's state machine for that session has moved on.
If the service validators are configured in 'active' mode, the detection of the error would result in a CourierException being thrown from the global filter, thus preventing the subsequent processing of the redelivered message - which may happen multiple times until the retry count expires.
One solution to this would be to detect that it is a redelivered message (I assume the Message has a redelivery flag???) - which can be used to ignore any service validator error.
However this would not resolve the problem if the initial processing of the message (when first delivered) resulted in other messages being sent.
Even if the redelivery Service Validator error is ignored, each of the sent messages (which will not be considered as re-deliveries, but fresh messages), will also result in Service Validator errors, as the service validators for those destinations would have previously processed the sent messages from the first invocation of the service. So again - if the service validators are configured in 'active' mode, then their delivery would be blocked.
This may be acceptable behaviour? If those messages were already sent to the target service descriptors, and possibly have already been processed, then maybe we don't want duplicates to be sent? If considered ok, then the only downside is that the Service Validator would report an out of sequence message - however this could potentially be traced back to the redelivery of the previous message.
One of the reasons for this issue is that the validation of the message, and subsequent processing of the message, are not performed in an atomic transaction - which could be rolled back if a failure was to occur. Not sure that this would be possible, given the current approach used for the Service Validators - i.e. global filters.
Therefore I believe there are only three solutions are the current time:
a) Disable the redelivery mechanism - but this could prevent the business apps from recovering in the event of periodic failure.
b) Only set the Service Validators in passive reporting mode.
c) Detect redelivery messages and ignore service validation failures for these messages
If (b) or (c) is taken, then it may mean some spurious out of sequence errors are reported, but it might be possible to precede the errors with a warning that a 'redelivered message is being re-processed, which may result in some out of sequence errors being generated'.