Anypoint Exchange

Home to the complete listing of connectors, templates, examples and APIs.
Discover and use proven assets built by the MuleSoft ecosystem, or add assets to a private
tenant of Anypoint Exchange for collaboration and sharing of internal best practices.

Learn more
Sign up
Content Based Routing

Content Based Routing

(0 reviews)

Learn how to route messages based on the logic you supply in the Choice Router.


Screenshot of the main flow in Anypoint Studio, view full image here

Description

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

Sample Use Case

The application receives an HTTP request and then 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 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  2014-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 then 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  2014-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  2014-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  2014-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  2014-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

Download
Log into Anypoint Platform to download this asset

Overview

Type
Example
Created by
MO
MuleSoft Organization
Published onJun 22, 2017

Versions

VersionRuntime version
1.4.03.x
1.3.33.7
1.2.03.6
1.1.03.5