July 30, 2023

cMessageFilter – Docs for ESB ESB 7.x

cMessageFilter

Filters the content of messages according to the specified criterion and routes the
filtered messages to the specified output channel. All messages that do not match the
criteria will be dropped.

For more information on the Camel Message Filter EIP: http://camel.apache.org/message-filter.html.

cMessageFilter Standard properties

These properties are used to configure cMessageFilter running in the Standard Job framework.

The Standard
cMessageFilter component belongs to the Routing family.

Basic
settings

Language

Select the language of the expression you use to filter your messages from None, Bean, Constant,
CorrelationID, EL, Groovy, Header,
JavaScript, JoSQL, JSonPath, JXPath,
MVEL, OGNL, PHP,
Property, Python, Ruby,
Simple, SpEL, SQL,
XPath, and XQuery.

For more information about how to use the languages to create an expression, see
the site http://camel.apache.org/languages.html.

Expression

Type in the expression to use to filter the
messages.

Add Namespaces

This option appears when XPath is
selected in the Language list.

Select this check box to add namespaces for the Xpath expression.
Click [+] to add as many namespaces
as required to the table and define the prefix and URI in the
corresponding columns.

Usage

Usage rule

cMessageFilter is used as a middle component in a
Route.

Connections Filter: Select this link to route the
filtered messages to the next endpoint.
  Route: Select this link to route all the
messages from the sender to the next endpoint.

Limitation

 n/a

Filtering messages according to a criterion

This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.

In this use case, we filter XML messages that are sent from the sending endpoint according
to a defined criterion: only the XML files in which the value of the
city node is Paris are sent to a folder
named Paris_only.

Of the four XML files used in this scenario, Message_1.xml and Message_4.xml
contain the city name of Paris. The following is an
example:

Dropping and linking the components

This scenario requires one cMessageFilter
component to filter the messages from the sender, one cFile component as the message sender, one cFile component to receiver the messages containing Paris, one cFile
component to receiver all the messages from the sender, and two cProcessor components to monitor the messages routed to
the two receivers.

cMessageFilter_1.png

  1. From the Connectivity folder of the Palette, drop three cFile components onto the design workspace, and label them
    Sender, Paris_only, and Unfiltered respectively to better identify their
    roles.
  2. From the Routing folder, drop a cMessageFilter component onto the design workspace, and
    label it Filter.
  3. From the Custom folder, drop two cProcessor components onto the design workspace, and label
    them Monitor_Paris and Monitor_Unfiltered respectively.
  4. Right-click the cFile component labeled
    Sender, select Row > Route from the
    contextual menu and click the cMessageFilter component.
  5. Right-click the cMessageFilter component,
    select Row > Filter from the contextual menu and click the cFile component labeled Paris_only. This endpoint will retrieve the messages that
    meet the defined criterion.
  6. Right-click the cMessageFilter component,
    select Row > Route from the contextual menu and click the cFile component labeled Unfiltered. This endpoint will collect all the messages,
    including those meeting the filter criterion. This connection is
    optional.
  7. Right-click the cFile component labeled
    Paris_only, select Row > Route from
    the contextual menu and click the cProcessor component labeled Monitor_Paris. Repeat this step to connect the cFile component labeled Unfiltered to the cProcessor component labeled Monitor_Unfiltered.

Configuring the components and connections

  1. Double-click the cFile component labeled
    Sender to open its Basic settings view in the Component tab.

    cMessageFilter_2.png

  2. In the Path field, specify the file path
    to message source.
  3. From the Encoding list, select the
    encoding type of your message files. Leave the other parameters as they
    are.
  4. Double-click the cMessageFilter component
    to open its Basic settings view in the
    Component tab.

    cMessageFilter_3.png

  5. Select the language of the expression you want to use to filter your
    messages, and enter an expression to define a criterion according to which
    you want to filter your messages.

    In this scenario, we want to sort out the XML files containing a city node
    with the value of Paris, so we select XPath
    from the Language list, and fill the in the
    Expression field with this expression:
    "/person[city='Paris']".
  6. Double-click the cFile component labeled
    Paris_only to open its Basic settings view in the Component view, and specify the path for the messages
    meeting the filter criterion in the Path
    field.

    cMessageFilter_4.png

    Repeat this step to define the path for all the messages from the sender
    in the cFile component labeled Unfiltered.
  7. Double-click the cProcessor component labeled Monitor_Paris to open its Basic settings view in the Component view, and customize the code in the Code area to display the file names of the
    messages that meet the filter criterion on the console:

    Repeat this step to customize the code in the cProcessor
    component labeled Monitor_Unfiltered to
    display the file names of all the messages from the sender.
  8. Press Ctrl+S to save your Route.

Viewing the code and executing the Route

  1. To have a look at the generated code, click the Code tab at the bottom of the design workspace.

    cMessageFilter_5.png

    As shown in this piece of code, messages from the sender are filtered by
    cMessageFilter_1 according to
    .xpath("/person[city='Paris']") and the messages matching
    the filter are send .to the endpoint Paris_only,
    while all messages are sent .to the endpoint
    Unfiltered.
  2. Click the Run view to display it and
    click the Run button to launch the
    execution of your Route.

    You can also press F6 to execute it.
    RESULT: The messages are filtered according to the defined criterion and the messages
    containing “Paris” are redirected to the Paris_only folder, all the messages, including
    those containing “Paris“, are sent to the Unfiltered folder.
    cMessageFilter_6.png


Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x