Handling failed events

In some cases, you may need to handle failed events within your collaboration instead of using the Flow Manager. For example, you may want to save off only those failed flows in a batch process for further management. There are APIs that allow a running collaboration to automatically handle failed events during collaboration processing. These APIs allow you to query, save, drop or resubmit failed events inside the collaboration. The APIs provide more flexibility than using the Flow Manager because you can build the processing within the business flow to automatically handle the failed events. This functionality allows a batch process to continue while providing the ability to resubmit or delete the failing events asynchronously.

Use the listed methods to provide your collaboration with failed event handling:

Saving a failed event

While handling errors during collaboration execution, you may decide that certain conditions require outside intervention before processing the event. In these cases, your collaboration logic could save the event for analysis and resubmission later. This capability allows the collaboration to complete processing objects that are correct to prevent delays in the overall process. For example, an order delivery system continues processing the correct items in an order so the warehouse can pull the good items without the incorrect items holding up the entire order.

Figure 27 shows the logic for an order delivery collaboration designed to process orders even if there are items in error. Notice that instead of saving the items immediately, the collaboration adds a failed business object to the parent business object and then returns success. When control returns to the main diagram, any existing children of the parent business object are saved using the saveFailedEvent() method on page saveFailedEvent().

Figure 27. Order delivery collaboration with the ability to save erroneous items

The figure is a flowchart that shows how exceptions are handled when processing an array of child business objects.

You could also build a parallel process to look for failed events, correct those failures and then resubmit them for processing. For additional information see:

Coding to save a failed event

The following example implements the logic shown in Figure 27.

Declaration:

// Define an empty parent BO:
BusObj iterOrderItem = new BusObj("OrderItem');
BusObj parentBo = new BusObj("SalesOrder");

In the action step to initialize the parent business object:

// Set values for parent BO:
// Set the values which are the same as triggeringBusObj
parentBo.set("SalesOrderId",triggeringBusObj.getString("SalesOrderId"));
parentBo.set("CustomerId",triggeringBusObj.getString("CustomerId"));
parentBo.set("OrderDate",triggeringBusObj.getString("OrderDate"));
//Set Verb to the parent bo
parentBo.setVerb(triggeringBusObj.getVerb());

In the iteration action step to save the child business object:

//Add the failed business object to parent bo
parentBo.set("OrderItems",iterOrderItem);

In the action step to check and save the parent business object:

// Check to see if the parent bo contains at least one child bo
BusObjArray boArray = parentBo.getBusOvjArray("OrderItems");
int nChildBo = 0;
if (boArray != null)
              nChildBo = boArray.size();
 
if(nChildBo>0) {
    // Call collaboration API to save the failed event
    saveFailedEvent(parentBO);
 
}

Enabling a collaboration to save failed events

To enable a collaboration to save failed events, update the collaboration template with an activity definition to detect and save the failed event. You do this directly in the action block or in the Activity Editor in the Java view.

Figure 28. Saving a failed event

The figure shows a code fragment for the properties of an action block. The code written is: // Check if the parent bo contains at least one child bo BusObjArray boArray = parentBo.getBusObjArray("OrderItems:); int nChildBo = 0; if (nChildBo != null) nChildBo = boArray.size(); parentBo.setVerb(triggeringBusObj.getVerb()); if (nChildBo>0) // Call collaboration API to save the failed event { saveFailedEvent(parentBo); }

Note:
There are no function blocks in the Activity Editor for queryFailedEvents(), dropFailedEvent(), resubmitFailedEvent() or saveFailedEvent().

Required data structures

To successfully implement failed event handling in your collaborations, you must import the following data structures:

These structures are automatically imported into your collaboration when compiling collaboration templates. For more information about the structures, see EventManagement package.

Resubmitting failed events

After saving failed events, your collaboration may resubmit those events for reprocessing. The InterChange Server uses the USER_GENERATED status to differentiate these failed events from other failed events that are not saved by the collaboration. When a collaboration resubmits a USER_GENERATED event the ICS changes the status of the event. The collaboration then processes the event anew. If the event fails again, the status is changed to USER_GENERATED and not FAILED so the collaboration can determine how to proceed in recovering from the second failure.

Note:
You can also use Flow Manager to manually locate and resubmit these events.

Copyright IBM Corp. 1997, 2004