Content Based Routing icon

Content Based Routing

(0 reviews)

home

This example shows Anypoint Studio's routing capabilities based on the content, and routes messages according to the logic you supply in the Choice Router. Flow variables are set and invoked using Mule Expression Language.

Example

The application receives an HTTP request and filters out any "favicon.ico" browser requests. It then transforms an inbound property into a flow variable. The message is routed according to the flow variable associated with the message. A new payload is set based on the routing logic, this payload is then sent as an HTTP response.

Set Up and Run the Example

  1. Open the example project in Anypoint Studio.
  2. Run this project as a Mule Application.
  3. Open any Web browser and go to:

     http://localhost:8081/?language=Spanish

    Your browser presents a message that reads "Hola!"Check the console log in Studio and look for a log message that reads

     INFO  2017-06-26 13:21:53,568 [[content-based-routing].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: The reply "Hola!" means "hello" in Spanish.
  4. In your browser’s address bar, replace URL with:

     http://localhost:8081/?language=French

    and press Enter.

    Your browser presents a message that reads "Bonjour!" Check the console log in Studio again and look for a log message that reads:

         INFO  2017-06-26 13:25:20,376 [[content-based-routing].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: The reply "Bonjour!" means "hello" in French.
  5. Try requesting the URL without a query parameter:

     http://localhost:8081

    Your browser presents a message that reads "Hello!"Check the console log in Studio again and look for a log message that reads

     INFO  2017-06-26 13:30:22,720 [[content-based-routing].connector.http.mule.default.receiver.04] org.mule.transformer.simple.AddFlowVariableTransformer: Variable with key "language", not found on message using "#[message.inboundProperties.language]". Since the value was marked optional, nothing was set on the message for this variable
    
     INFO  2017-06-26 13:30:22,721 [[content-based-routing].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: No language specified. Using English as a default.
    
     INFO  2017-06-26 13:30:22,722 [[content-based-routing].connector.http.mule.default.receiver.04] org.mule.api.processor.LoggerMessageProcessor: The reply "Hello!" means "hello" in English.

Documentation

Read full documentation in GitHub

Examples to Try Next

If you understood this example
Querying a MySQL Database - Learn how to use the database connector to query a MySQL database.View
If you struggled with this example
Mule Expression Language Basics - An introduction to most of the basic implementations of Mule Expression Language.View
Filtering a Message - Learn how to use filter components to filter an incoming message.View

Reviews

TypeExample
OrganizationMulesoft Inc.
Published by
MuleSoft Organization
Published onMar 17, 2018
Asset overview

Asset versions for 1.4.x

Asset versions
VersionActions
1.4.0