Class RouteOnAttribute

java.lang.Object
org.apache.nifi.components.AbstractConfigurableComponent
org.apache.nifi.processor.AbstractSessionFactoryProcessor
org.apache.nifi.processor.AbstractProcessor
org.apache.nifi.processors.standard.RouteOnAttribute
All Implemented Interfaces:
org.apache.nifi.components.ConfigurableComponent, org.apache.nifi.processor.Processor

@SideEffectFree @SupportsBatching(defaultDuration=TWENTY_FIVE_MILLIS) @InputRequirement(INPUT_REQUIRED) @Tags({"attributes","routing","Attribute Expression Language","regexp","regex","Regular Expression","Expression Language","find","text","string","search","filter","detect"}) @CapabilityDescription("Routes FlowFiles based on their Attributes using the Attribute Expression Language") @DynamicProperty(name="Relationship Name", value="Expression Language expression that returns a boolean value indicating whether or not the FlowFile should be routed to this Relationship", expressionLanguageScope=FLOWFILE_ATTRIBUTES, description="Routes FlowFiles whose attributes match the Expression Language specified in the Dynamic Property Value to the Relationship specified in the Dynamic Property Key") @DynamicRelationship(name="Name from Dynamic Property", description="FlowFiles that match the Dynamic Property\'s Attribute Expression Language") @WritesAttributes(@WritesAttribute(attribute="RouteOnAttribute.Route",description="The relation to which the FlowFile was routed")) @UseCase(description="Route data to one or more relationships based on its attributes using the NiFi Expression Language.",keywords={"attributes","routing","expression language"},configuration="Set the \"Routing Strategy\" property to \"Route to Property name\".\nFor each route that a FlowFile might be routed to, add a new property. The name of the property should describe the route.\nThe value of the property is an Attribute Expression Language expression that returns a boolean value indicating whether or not a given FlowFile will be routed to the associated relationship.\n\nFor example, we might route data based on its file extension using the following properties:\n - \"Routing Strategy\" = \"Route to Property Name\"\n - \"jpg\" = \"${filename:endsWith(\'.jpg\')}\"\n - \"png\" = \"${filename:endsWith(\'.png\')}\"\n - \"pdf\" = \"${filename:endsWith(\'.pdf\')}\"\n\nThe Processor will now have 3 relationships: `jpg`, `png`, and `pdf`. Each of these should be connected to the appropriate downstream processor.\n") @UseCase(description="Keep data only if its attributes meet some criteria, such as its filename ends with .txt.",keywords={"keep","filter","remove","delete","expression language"},configuration="Add a new property for each condition that must be satisfied in order to keep the data.\nIf the data should be kept in the case that any of the provided conditions is met, set the \"Routing Strategy\" property to \"Route to \'matched\' if any matches\".\nIf all conditions must be met in order to keep the data, set the \"Routing Strategy\" property to \"Route to \'matched\' if all match\".\n\nFor example, to keep files whose filename ends with .txt and have a file size of at least 1000 bytes, we will use the following properties:\n - \"ends_with_txt\" = \"${filename:endsWith(\'.txt\')}\"\n - \"large_enough\" = \"${fileSize:ge(1000)}\n - \"Routing Strategy\" = \"Route to \'matched\' if all match\"\n\nAuto-terminate the \'unmatched\' relationship.\nConnect the \'matched\' relationship to the next processor in the flow.\n") @UseCase(description="Discard or drop a file based on attributes, such as filename.",keywords={"discard","drop","filter","remove","delete","expression language"},configuration="Add a new property for each condition that must be satisfied in order to drop the data.\nIf the data should be dropped in the case that any of the provided conditions is met, set the \"Routing Strategy\" property to \"Route to \'matched\' if any matches\".\nIf all conditions must be met in order to drop the data, set the \"Routing Strategy\" property to \"Route to \'matched\' if all match\".\n\nHere are a couple of examples for configuring the properties:\n Example 1 Use Case: Data should be dropped if its \"uuid\" attribute has an \'a\' in it or ends with \'0\'.\n Here, we will use the following properties:\n - \"has_a\" = \"${uuid:contains(\'a\')}\"\n - \"ends_with_0\" = \"${uuid:endsWith(\'0\')}\n - \"Routing Strategy\" = \"Route to \'matched\' if any matches\"\n Example 2 Use Case: Data should be dropped if its \'uuid\' attribute has an \'a\' AND it ends with a \'1\'.\n Here, we will use the following properties:\n - \"has_a\" = \"${uuid:contains(\'a\')}\"\n - \"ends_with_1\" = \"${uuid:endsWith(\'1\')}\n - \"Routing Strategy\" = \"Route to \'matched\' if all match\"\n\nAuto-terminate the \'matched\' relationship.\nConnect the \'unmatched\' relationship to the next processor in the flow.\n") @MultiProcessorUseCase(description="Route record-oriented data based on whether or not the record\'s values meet some criteria",keywords={"record","route","content","data"},configurations={@ProcessorConfiguration(processorClass=PartitionRecord.class,configuration="Choose a RecordReader that is appropriate based on the format of the incoming data.\nChoose a RecordWriter that writes the data in the desired output format.\n\nAdd a single additional property. The name of the property should describe the criteria to route on. The property\'s value should be a RecordPath that returns `true` if the Record meets the criteria or `false` otherwise. This adds a new attribute to the FlowFile whose name is equal to the property name.\n\nConnect the \'success\' Relationship to RouteOnAttribute.\n"),@ProcessorConfiguration(processorClass=RouteOnAttribute.class,configuration="Set \"Routing Strategy\" to \"Route to Property name\"\n\nAdd two additional properties. For the first one, the name of the property should describe data that matches the criteria. The value is an Expression Language expression that checks if the attribute added by the PartitionRecord processor has a value of `true`. For example, `${criteria:equals(\'true\')}`.\nThe second property should have a name that describes data that does not match the criteria. The value is an Expression Language that evaluates to the opposite of the first property value. For example, `${criteria:equals(\'true\'):not()}`.\n\nConnect each of the newly created Relationships to the appropriate downstream processors.\n")}) public class RouteOnAttribute extends org.apache.nifi.processor.AbstractProcessor

This processor routes a FlowFile based on its flow file attributes by using the Attribute Expression Language. The Expression Language is used by adding Optional Properties to the processor. The name of the Property indicates the name of the relationship to which a FlowFile will be routed if matched. The value of the Property indicates an Attribute Expression Language Expression that will be used to determine whether or not a given FlowFile will be routed to the associated relationship. If multiple expressions match a FlowFile's attributes, that FlowFile will be cloned and routed to each corresponding relationship. If none of the supplied expressions matches for a given FlowFile, that FlowFile will be routed to the 'unmatched' relationship.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private String
     
    private Set<String>
     
    private static final List<org.apache.nifi.components.PropertyDescriptor>
     
    private Map<org.apache.nifi.processor.Relationship,org.apache.nifi.components.PropertyValue>
    Cache of dynamic properties set during onScheduled(ProcessContext) for quick access in onTrigger(ProcessContext, ProcessSession)
    static final org.apache.nifi.processor.Relationship
     
    static final org.apache.nifi.processor.Relationship
     
    private final AtomicReference<Set<org.apache.nifi.processor.Relationship>>
     
    static final org.apache.nifi.components.AllowableValue
     
    static final org.apache.nifi.components.AllowableValue
     
    static final String
     
    static final org.apache.nifi.components.AllowableValue
     
    static final org.apache.nifi.components.PropertyDescriptor
     
    private static final String
     
    private static final String
     
    private static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Set<org.apache.nifi.processor.Relationship>
     
    protected org.apache.nifi.components.PropertyDescriptor
     
    protected List<org.apache.nifi.components.PropertyDescriptor>
     
    void
    onPropertyModified(org.apache.nifi.components.PropertyDescriptor descriptor, String oldValue, String newValue)
     
    void
    onScheduled(org.apache.nifi.processor.ProcessContext context)
    When this processor is scheduled, update the dynamic properties into the map for quick access during each onTrigger call
    void
    onTrigger(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session)
     

    Methods inherited from class org.apache.nifi.processor.AbstractProcessor

    onTrigger

    Methods inherited from class org.apache.nifi.processor.AbstractSessionFactoryProcessor

    getControllerServiceLookup, getIdentifier, getLogger, getNodeTypeProvider, init, initialize, isConfigurationRestored, isScheduled, toString, updateConfiguredRestoredTrue, updateScheduledFalse, updateScheduledTrue

    Methods inherited from class org.apache.nifi.components.AbstractConfigurableComponent

    customValidate, equals, getPropertyDescriptor, getPropertyDescriptors, hashCode, validate

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.nifi.components.ConfigurableComponent

    getPropertyDescriptor, getPropertyDescriptors, validate

    Methods inherited from interface org.apache.nifi.processor.Processor

    isStateful, migrateProperties, migrateRelationships
  • Field Details

    • ROUTE_ATTRIBUTE_KEY

      public static final String ROUTE_ATTRIBUTE_KEY
      See Also:
    • routeAllMatchValue

      private static final String routeAllMatchValue
      See Also:
    • routeAnyMatches

      private static final String routeAnyMatches
      See Also:
    • routePropertyNameValue

      private static final String routePropertyNameValue
      See Also:
    • ROUTE_PROPERTY_NAME

      public static final org.apache.nifi.components.AllowableValue ROUTE_PROPERTY_NAME
    • ROUTE_ALL_MATCH

      public static final org.apache.nifi.components.AllowableValue ROUTE_ALL_MATCH
    • ROUTE_ANY_MATCHES

      public static final org.apache.nifi.components.AllowableValue ROUTE_ANY_MATCHES
    • ROUTE_STRATEGY

      public static final org.apache.nifi.components.PropertyDescriptor ROUTE_STRATEGY
    • PROPERTY_DESCRIPTORS

      private static final List<org.apache.nifi.components.PropertyDescriptor> PROPERTY_DESCRIPTORS
    • REL_NO_MATCH

      public static final org.apache.nifi.processor.Relationship REL_NO_MATCH
    • REL_MATCH

      public static final org.apache.nifi.processor.Relationship REL_MATCH
    • relationships

      private final AtomicReference<Set<org.apache.nifi.processor.Relationship>> relationships
    • configuredRouteStrategy

      private volatile String configuredRouteStrategy
    • dynamicPropertyNames

      private volatile Set<String> dynamicPropertyNames
    • propertyMap

      private volatile Map<org.apache.nifi.processor.Relationship,org.apache.nifi.components.PropertyValue> propertyMap
      Cache of dynamic properties set during onScheduled(ProcessContext) for quick access in onTrigger(ProcessContext, ProcessSession)
  • Constructor Details

    • RouteOnAttribute

      public RouteOnAttribute()
  • Method Details

    • getRelationships

      public Set<org.apache.nifi.processor.Relationship> getRelationships()
      Specified by:
      getRelationships in interface org.apache.nifi.processor.Processor
      Overrides:
      getRelationships in class org.apache.nifi.processor.AbstractSessionFactoryProcessor
    • getSupportedPropertyDescriptors

      protected List<org.apache.nifi.components.PropertyDescriptor> getSupportedPropertyDescriptors()
      Overrides:
      getSupportedPropertyDescriptors in class org.apache.nifi.components.AbstractConfigurableComponent
    • getSupportedDynamicPropertyDescriptor

      protected org.apache.nifi.components.PropertyDescriptor getSupportedDynamicPropertyDescriptor(String propertyDescriptorName)
      Overrides:
      getSupportedDynamicPropertyDescriptor in class org.apache.nifi.components.AbstractConfigurableComponent
    • onPropertyModified

      public void onPropertyModified(org.apache.nifi.components.PropertyDescriptor descriptor, String oldValue, String newValue)
      Specified by:
      onPropertyModified in interface org.apache.nifi.components.ConfigurableComponent
      Overrides:
      onPropertyModified in class org.apache.nifi.components.AbstractConfigurableComponent
    • onScheduled

      @OnScheduled public void onScheduled(org.apache.nifi.processor.ProcessContext context)
      When this processor is scheduled, update the dynamic properties into the map for quick access during each onTrigger call
      Parameters:
      context - ProcessContext used to retrieve dynamic properties
    • onTrigger

      public void onTrigger(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session)
      Specified by:
      onTrigger in class org.apache.nifi.processor.AbstractProcessor