Content Based Routing
home
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
- Open the example project in studio.
- Run this project as a Mule Application.
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.
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.
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 |