Data Router Component
The Data Router Component accepts data on a single input channel and forwards it to one of its outputs based on routing logic defined in a Groovy script. The script should implement the ScriptedDataRouter interface, which defines the required routeData method. The routeData method receives the input channel name and data item, and returns the name of the output channel to route to.
Figure 1 - Data Router block diagram showing the data flow between the inputs and outputs. The routing logic makes decisions on which output a data item goes to based on its internal logic.
Data Governance
This component does not modify the Data Governance status of any items.
Auditing
Scripts can send events to the deployment’s audit logs using an AuditLogger object. If your script needs to send audit logs, extend the com.datashyft.pipeline.scripting.ScriptedAuditor abstract class, which provides access to an AuditLogger instance via its getAuditLogger() method. The AuditLogger object defines a single method, sendAuditLog(category, message) , which sends messages to the deployment’s audit log — for example:
this.auditLogger.sendAuditLog(LogCategory.INFO, "Discarding an item")
The available categories are defined in the LogCategory class and include DEBUG , INFO , WARN , and ERROR .
Exception Handling
If the script cannot process a data item immediately, it can signal this to the deployment by throwing a ProcessAbortedException from the routeData method. Throwing this exception causes the item to be requeued for later processing. If the exception includes a retry delay parameter, the component waits at least that long before retrying. The exception can also specify alternate output data to be emitted while requeuing the original input.
Example Script
import com.datashyft.core.model.dataobjects.PipelineData;
import com.datashyft.pipeline.util.AbstractGroovyComponent.AuditLogger;
import com.datashyft.pipeline.scripting.ScriptedDataRouter;
// @OutputChannel("secure", "PipelineData")
// @OutputChannel("insecure", "PipelineData")
class DataRouterExample implements ScriptedDataRouter {
String routeData(String inputChannelName, PipelineData input) {
if (input.hasTag("secret")) {
return "secure";
} else {
return "insecure";
}
}
}
Input Channels
default – PipelineData items received on this channel are forwarded to one of the component’s output channels based on the logic in the routing script.
Output Channels
channelN – Custom output channels can be defined by the pipeline creator. This custom output can then be referenced by the routing rules. See the Custom Input and Output Channels page for details on how to specify the custom input channels.
error — Outputs an ErrorOutput object for any errors that occur executing the routing script.
Parameters
script – A Groovy script containing a routeData() method that returns the name of the output channel the input data should be sent to. If a non-existent output channel is specified, the data is discarded.