Mule ESB-Content-Based Routing Tutorial (2)

Source: Internet
Author: User
Tags mule esb

Undertake Mule ESB-Content-Based Routing Tutorial (1)
5. Run the application
After creating, configuring, and saving your new application, you can run it on the embedded Mule server (including in Mule Studio as part of the bundled download ). 1. In the Package Explorer pane, right-click the Basic Tutorial. mflow file and choose Run As> Mule Application. (If you have not saved it, Mule will prompt you to save it now. 2. Mule immediately displays the running progress gear, starts your application, and enables it to run. After the startup process is complete, MuleStudio reads a message from the console and starts the application "cbr_tutorial ".


6. Use Application 1. Open any web browser and navigate to http: // localhost: 8081 /? Language = Spanish2 your browser will display a message that says "Hola! "3. Check your Mule Studio console and you will find a log that says,
INFO 2013-11-26 11:30:18, 790 [[cbr_tutorial]. connector. http. mule. default. receiver.03] org. mule. api. processor. LoggerMessageProcessor: The reply "Hola! "Means" hello "in Spanish.
4. In the address bar of your browser, replace the url with http: // localhost: 8081 /? Language = French, and press Enter. 5. Your browser will display a message that says "Bonjour! "6. Check your Mule Studio console and you will find a log with the following information:
INFO 2013-11-26 11:36:38, 826 [[cbr_tutorial]. connector. http. mule. default. receiver.02] org. mule. api. processor. LoggerMessageProcessor: The reply "Bonjour! "Means" hello "in French.
7. Try not to use any parameters to request this url: http: // localhost: 8081 8. A message is displayed in your browser, which says "Hello! "9. Check your Mule Studio console and you will find a log that says:
INFO 2013-11-26 11:36:53, 709 [[cbr_tutorial]. connector. http. mule. default. receiver.02] org. mule. api. processor. LoggerMessageProcessor: The reply "Hello! "Means" hello "in English.
10. This last log message is not very interesting and cannot provide information. You can modify it in an extra bonus task, as shown below.
7. Edit the running application
If you modify and save the changes when the application is running. Mule will automatically Redeploy your application, which is usually called Hot deployment.
Add another log component to the Information Processor chain and place it in the default options within the selected range.

...            <choice doc:name="Choice">            <when expression="#[flowVars['language'] == 'Spanish']">                <set-payload value="Hola!" doc:name="Reply in Spanish"/>            </when>            <when expression="#[flowVars['language'] == 'French']">                <set-payload value="Bonjour!" doc:name="Reply in French"/>            </when>            <otherwise>                <logger message="No language specified. Using English as a default." level="INFO" doc:name="Logger"/>                <set-variable variableName="language" value="English" doc:name="Set Language to English"/>                <set-payload value="Hello!" doc:name="Reply in English"/>            </otherwise>        </choice>...

Click the console tab under the canvas to view the application running logs, and then click File> Save to save your application. Observe the console, and note that Mule has immediately redeployed your application. The INFO message displayed in the log indicates that the application is redeployed due to changes.


To test this change and verify that your log component works properly, return to the browser and request http: // localhost: 8081 again. Check the Sudio console log and find a log message that says: INFO 13:03:28, 688
[[Cbr_tutorial]. connector. http. mule. default. receiver.02] org. mule. api. processor. LoggerMessageProcessor: No language specified. Using English as a default.
You modified your application, and the hot deployment was successful!
8. Add a sub-process
You have used a simple and limited option to route messages to your application. In this example, the most complex routing option only has three message processors in one chain, but in more complex applications, there may be more message processing steps, it may contain additional branch or routing logic. To make your code organized and build it into reusable blocks, you can move the processed part to an independent process or sub-process, connect these processes or sub-processes with the process Reference Components and call them as needed.
What is the difference between a process and a sub-process? Both processes and subprocesses are composed of several separate component units that you link to, and control the receipt, processing, and routing of messages. To accomplish the goal of this tutorial, you can use one process or sub-process to complete the following steps, but in a more advanced scenario, you may need one or more. The process has more advanced configuration options, such as the ability to change the processing policy and define an exception policy. A sub-process always has a synchronization processing policy that inherits the exception policy of the Process referenced by her. Both processes and subprocesses are called using the process reference component.
Edit your application, add a sub-process, and move the options in the default router selection box to the sub-process. To do this, you need to add two component blocks to your application: * a process reference component that calls another process in the application. In the component section of the component board, you can find it * a sub-process scope. This will create another process in your application. You can refer to the above process reference component. Find it in the scope of the element board.
It is particularly easy to move a message processor to a sub-Flow Using the visual editor of Studio. 1. Press Shift and click the three message processors in the default box of the selected range. The three message processors are highlighted, right-click them, and select extract them to the. sub-process.

2. Studio prompts you to name your sub-process. You can give it a unique name at will. This example uses the name CBR_TutorialFlow2. 3. Create a sub-process under your existing process. Replace the content in the default box with the reference component of the process.

Your complete application XML should be as follows:

<?xml version="1.0" encoding="UTF-8"?><mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">    <flow name="CBR_TutorialFlow1" doc:name="CBR_TutorialFlow1">        

Save your project and observe the console because it redeploys the application you have changed. Repeat the application used in the preceding steps.
You will notice that the result is not changed compared with the previous one. Organize the three message processors to a sub-process, and then call the process using the process reference component without affecting the functions of the application. However, as you will see in the additional task section below, separating the branch Processing Section and making it a sub-process can help your code maintain (and the visual representation on the Studio canvas) neat and easy to read. For more information about how to use multiple flows or subflows to organize some actual use cases of your application, see some moderate and high-complexity Mule examples, such as processing and routing instances in Foreach.
Tired today. Come here first. Continue the next day.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.