Navigation

1-5 Handling Multiple Types of Content

If you have more than one type of content that you want to handle in a single flow, there are a few ways to do it.

Method 1: Use either EvaluateXPath or EvaluateJsonPath to test for the first type of content. The "matched" relationship will route the matching content, "unmatched" will have content of the same type (XML/JSON) but which does not contain the specified path and the "failure" relationship will route content that is not of that type. In the example below, we route both the "unmatched" and "failure" relationships of EvaluateXPath to the EvaluateJsonPath processor.

Method 2: Use the IdentifyMimeType processor to store the MIME type as a property, then use the RouteOnAttribute processor to send the content to separate XML and JSON handlers.

Method 3: If file extensions are reliable, use RouteOnAttribute with route properties on filename property. e.g. XML: ${filename:endsWith('.xml')}. Flow is the same as Method 2 except that IdentityMimeType can be removed and GetFile connected directly to RouteOnAttribute.

Method 1

  • Download Template
  • Processors:
    • GetFile – reads files from a watched directory
      • Properties
        • Input Directory: /some/path
    • EvaluateXPath - Store values from XML in FlowFile properties
      • Properties
        • Destination: flowfile-attribute
        • ml.xml.id: string(/*[local-name()='message']/*[local-name()='message_xml']/*[local-name()='id']) (custom property)
      • Settings
        • Automatically Terminate Relationships: failure, unmatched
    • UpdateAttribute (after EvaluateXPath)
      • Properties
        • ml.uri: /messages/${ml.xml.id}.xml (custom property)
    • EvaluateJsonPath - Store values from JSON in FlowFile properties
      • Properties
        • Destination: flowfile-attribute
        • ml.json.id: $.id (custom property)
      • Settings
        • Automatically Terminate Relationships: failure, unmatched
    • UpdateAttribute (after EvaluateJsonPath)
      • Properties
        • ml.uri: /json/${ml.json.id}.xml (custom property)
    • PutMarkLogic
      • Properties
        • URI Attribute Name: ml.uri
      • Settings
        • Automatically Terminate Relationships: failure, unmatched

Method 2

  • Download Template
  • Processors:
    • GetFile – reads files from a watched directory
      • Properties
        • Input Directory: /some/path
    • IdentifyMimeType – stores the MIME type in the "mime.type" property
      • Properties
        • (none)
    • RouteOnAttribute – allows for creation of custom routes based on properties, such as mime.type
      • Properties
        • ml.uri: /messages/${ml.xml.id}.xml (custom property)
    • EvaluateXPath - Store values from XML in FlowFile properties
      • Properties
        • Destination: flowfile-attribute
        • ml.xml.id: string(/*[local-name()='message']/*[local-name()='message_xml']/*[local-name()='id']) (custom property)
        • matched: UpdateAttribute (1)
        • unmatched, failure: EvaluateJsonPath
    • UpdateAttribute (after EvaluateXPath)
      • Properties
        • ml.uri: /messages/${ml.xml.id}.xml (custom property)
    • EvaluateJsonPath - Store values from JSON in FlowFile properties
      • Properties
        • Destination: flowfile-attribute
        • ml.xml.id: string(/*[local-name()='message']/*[local-name()='message_xml']/*[local-name()='id']) (custom property)
      • Relationships
        • matched: UpdateAttribute (1)
        • unmatched, failure: EvaluateJsonPath
    • UpdateAttribute (after EvaluateJsonPath)
      • Properties
        • ml.uri: /json/${ml.json.id}.xml (custom property)
    • InvokeHTTP – HTTP PUT to MarkLogic REST API /LATEST/documents
      • Properties
        • URI Attribute Name: ml.uri
      • Settings
        • Automatically Terminate Relationships: failure, success