Skip to main content

CREATE ROUTER

CREATE ROUTER <name> INPUT FROM <stream name> [ AS <alias> ]
CASE
  WHEN <expression> THEN ROUTE TO <stream name>,...
[ ELSE ROUTE TO <stream name> ] 
;

Distributes events from an input stream among two or more output streams based on user-defined criteria.

  • If an event matches more than one WHEN expression, a copy will be output to each of the corresponding streams.

  • If an event matches none of the WHEN expressions, it will be output to the ELSE stream.

  • If no ELSE clause is specified, events that do not match any of the WHEN expressions are discarded.

See CREATE CQ (query), Operators, and Functions for information about writing expressions.CREATE CQ (query)

For example:

CREATE ROUTER myRouter INPUT FROM mySourceStream AS src 
CASE
  WHEN TO_INT(src.data[1]) < 150 THEN ROUTE TO stream_one,
  WHEN TO_INT(src.data[1]) >= 150 THEN ROUTE TO stream_two,
  WHEN meta(src,"TableName").toString() like 'QATEST.TABLE_%' THEN ROUTE TO stream_three,
ELSE ROUTE TO stream_else;

Routers may be created in the Flow Designer. Known issue (DEV-36792): if your WHEN expression uses a function that requires an alias for the input stream, you cannot create the router in the Flow Designer, instead you must create the router in TQL and import it.

When you add a new router to an application and select the input stream, you will see something like this (the fields vary depending on the input stream's type):

FlowDesignerRouter1.png

Click Edit using TQL if you prefer to enter the expression as code.

  • Attribute: for an input stream of a user-defined events, select a field. For an input stream of type WAEvent, enter an appropriate expression, typically using a DATA() or META() function.

  • Condition: for numeric fields or dates, select Less than, Less than or equal, Equal, Greater than or equal, or Greater than; for strings, select Like or Not like. If you require a more complex expression, click Edit using TQL and write the expression manually.

  • Value: the value to be compared with the specified Attribute using the selected Condition.

  • Data type: specify the data type of the selected Attribute.

  • Output stream: select the output stream or enter a name to create a new stream. There should be separate output streams for each WHEN and the ELSE.

  • Click Add condition to specify as many additional WHEN clauses as you need.

When you view a saved router, your WHEN expressions will be displayed as read-only text summary..

router_read_only_TQL.png

To edit the expression, click the to the left of When.

router_edit_UI.png

To edit the expression as TQL, click Edit using TQL > Continue. Note that once you do this you will not be able to return to editing using the UI.

router_edit_TQL.png