Creating Routing PeopleCode

OnRouteSend (and OnRouteReceive) are PeopleCode methods that are tied to the message for routing, based on the message contents. If you want the contents of the message (such as a message chunking field value) to determine the subscribing nodes that should receive the message, OnRouteReceive PeopleCode must contain the logic to examine the message and return a list of subscribing nodes.

The OnRouteSend and OnRouteReceive methods are contained in the IRouter application class. The IRouter application class is located in PeopleSoft Application Designer in the Integration subpackage of the PS_PT application package.

PeopleCode functions provided by common components, GetNodes and RtnNodes, work with any message and chunking rule. For a given message, these nodes select the chunking rule for the publish rule that is assigned to the message.

The functions:

  • Build SQL based on the chunking fields as defined in the chunking table.

  • Extract chunking field values from the message.

  • Run the associated SQL.

  • Compare the array of nodes returned to the application server against the list of nodes for the message channel.

  • Create a publish contract for nodes in both arrays.

    You can override the publish rule from the message, specifying an optional parameter when calling the functions.

  • Return an array of nodes that is based on the nodes that are assigned to the message channel if the publish rule is invalid or does not contain a chunking rule.

    Returning an array of nodes enables the functions to work regardless of whether chunking is set up for the publish rule.

To route any message that uses chunking, use generic PeopleCode functions.

These functions are called from routing PeopleCode:

Field or Control Description

GetNodes

Returns an array of nodes to the application server.

Use this function for integrations on PeopleTools 8.47 and earlier releases.

RtnNodes

Returns an array of nodes to the calling PeopleCode.

Use this function for integrations on PeopleTools 8.47 and earlier releases.

RtnMsgNodes

Returns an array of nodes of datatype Any to the calling PeopleCode.

Use this function for integrations on PeopleTools 8.48 and higher releases.

These functions are internal functions:

Field or Control Description

FndNodes

Builds an array of nodes for the message.

GetPubRule

Selects the chunking rule for the publish rule.

GetChunkInfo

Selects the chunk table for the chunking rule.

BuildSQL

Builds SQL to select nodes from the chunking table for specific chunking field values from the message.

GetValue

Gets the chunking field values from the message.

HasNodes

Determines whether a chunking field is mapped to any nodes for a particular chunking rule.

The following code example shows the logic that you can add to SavePostChange PeopleCode for the Customer_General component to verify that the setID can publish the message by calling the HasNodes() function:

Declare Function HasNodes PeopleCode FUNCLIB_EOEIP.PUBLISH_ROUTE_PC 
FieldFormula;
Local Message &MSG;
Local Rowset &RS0;
Local string &PublishRule;
&MSG = CreateMessage(MESSAGE.CUSTOMER_MSG);
/* Check if message is active */
If &MSG.IsActive Then
     &RS0 = GetLevel0();
     &PublishRule = "CUSTOMER_SYNC";
     /* Call function passing publish rule and rowset, which returns 
     true if this setID can publish the message */
     If (HasNodes(&PublishRule, &RSO)) Then
          &RS0 = GetLevel0();
          &MSG.CopyRowsetDelta(&RS0);
          &MSG.Publish();
     End-If;
End-If;

The following code example shows the logic that you can add to service operation APC handler PeopleCode to chunk the message by nodes as defined in the chunking rules by calling the RtnMsgNodes function:


import PS_PT:Integration:IRouter;

class ChunkSetidByNode implements PS_PT:Integration:IRouter
   method RoutingHandler();
   property array of any destinationNodes;
   method OnRouteSend(&_MSG As Message) Returns integer;
   method OnError(&_MSG As Message);
end-class;

Declare Function RtnMsgNodes PeopleCode FUNCLIB_EOEIP.PUBLISH_ROUTE_PC 
FieldFormula;

/* constructor */
method RoutingHandler
end-method;

method OnRouteSend
   /+ &_MSG as Message +/
   /+ Returns Integer +/
   /+ Extends/implements PS_PT:Integration:IRouter.OnRouteSend +/
   /* Variable Declaration */
   Local string &PublishRule;
   %This.destinationNodes = RtnMsgNodes(&PublishRule, &_MSG);
   If %This.destinationNodes.Len > 0 Then
      Return (%IntBroker_ROUTE_SOME);
   Else
      Return (%IntBroker_ROUTE_ALL);
   End-If;
end-method;

/** If an error occurs the OnError method if implemented will be automatically⇒
 invoked. The type of exception can be viewed by using the Message object to⇒
 retrieve the Exception object (&Message.IBException)
  * @param   MSG Message object containing the operation instance where⇒
 the error occured while being routed
  */
method OnError
   /+ &_MSG as Message +/
   /+ Extends/implements PS_PT:Integration:IRouter.OnError +/
end-method;