Version: 17.01
Supported Since: 17.01
A Switch processing element used in combination with several Case processing elements is considered as a Switch-Case processor. Theoretically the behaviour of this is similar to a switch block of a high level programming language such as Java, where this processor accepts message contexts and directs them to different processing branches based on a specific condition.
In the following use case, the requirement is to read a message from a JMS queue and based on the value of the header X_HEADER, dispatch it to 3 different JMS queues. If the header value is foo, dispatch to queue 1, if the header value is bar, dispatch to queue 2 or if the header value is hello, dispatch to queue 3.
To achieve this, the message context provided from JMS Ingress Connector is handed over to a Switch processing element. As shown in the above configuration, Switch element is configured to have a HEADER Predicate Type and the Variable Name is set to "X_HEADER". Then the Predicate Type is set to EQUALS.
The Case Value of the three Case processing elements are set to values "foo", "bar" and "hello" respectively.
So when a message context is received, the processing element executes Equals predicate between the value of the
"X_HEADER" header of the message and the case value of each Case processing element. If the predicate is evaluated true
to a particular case element, the message context is sent to that case branch, hence dispatching to the
JMS Egress Connector connected to that branch.
If none of the case elements evaluated true
, the message context is sent to the default outport sending it to an
Exceptional Flow End processor which will mark the flow as failed
with an IntegrationRuntime
exception.
Please note that in order to preserve simplicity, JMS transactions haven’t been used in this sample flow. If transactions has been used, the message will be rolled back to the source JMS queue in the default case as the message flow is failed. |
Case |
All the Case elements should be connected to this outport and the message context will be sent to the first case
element that evaluates to |
Default |
The message context will be sent to this outport if none of the case values evaluated to |
On Exception |
The message context will be sent to this outport if any exception occurred while processing |
Predicate Type * |
Basic |
The type of predicate to be used for the evaluation. The following predicate types are supported.
|
||
Variable Name * |
Basic |
The interpretation of this parameter’s value depends on the selected predicate type.
|
||
Variable Type * |
Basic |
The type of the variables used in the predicate. One of the following types can be selected as the value of this parameter.
|
||
Predicate Function * |
Basic |
The predicate function to be used to compare the value resolved (using the above predicate type and the variable name) and the case value in each connected case element. One of the following predicate functions can be selected as the value of this parameter.
|
||
Namespaces |
Basic |
If the predicate type is CONTENT (where an XPath value is used for the condition), this parameter specifies an optional map (defined as a resource) with namespace prefixes (as keys) and namespaces (as values) used within the XPath expression |
Case Value * |
Basic |
The selected predicate of the switch element will be executed against the value of this parameter to evaluate whether this case branch matches the criteria.
|