WebService Consumer Element
This is a new feature for MuleESB 3.5.0 and it has a really nice integration with studio. Traditionally, in order to consume a SOAP web service from Mule, one would have needed to either generate a Java-based client or deal with raw SOAP XML payloads. Now, by simply specifying a WSDL, studio helps us presenting the available bindings and ports. Finally, thanks to Data sense and DataMapper (these features were present on previous versions of MuleStudio), you can easily populate the request and take advantage of the response.
This is how our flow would look like:
This approach is very lightweight and is by far easier than the previous approach with the CXF Module.
Request-Reply Element
Finally, request-reply has gained visual support, this element is particularly useful when we have to call asynchronous services but need to synchronously wait for the response. This element is not new but for long time has been something we'd need to go to the XML view to take advantage of. Now we have nice visual integration.
This is a sample flow demonstrating the use of the request-reply element:
This flow places a call into a VM queue (could be JMS as well) and waits for the response in the reply queue. This allows us to synchronize the call to the second flow within the first one but at the same time keep it's asynchronous nature for other consumers.
Scatter-Gather
This element allow us to run multiple routes but in parallel, and take advantage of the result, this is, an asynchronous counterpart for the existing 'All' router. Previously, this behavior could have only been achieved in an 'artificial' way, this is mixing request-reply, all and collection aggregator. Now it is available to use in a general form.
Here are sample flows showing the parallel processing of this component:
The invoked flow, sleeps for 2 seconds and produces a log statement before the sleep happens.
Database Access Reloaded
Previously, MuleESB had the JDBC transport, which was sort of un-natural for new MuleESB versions but at the time of it's release Mule didn't have features such as poll or watermark. Now, database access has been transformed into a shiny module that tackles access to databases in a very consistent and easy way. The following example shows how to run a query every 30 seconds and log the resulting records.
This module allows easy creation of parameterized queries (before these queries were also possible but somehow unnatural to produce), easy access to stored procedures and other interesting features.
Source Code
The following snippet is the XML source for the previous examples that demonstrates a more comprehensive view of the settings applied to the components:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:ws="http://www.mulesoft.org/schema/mule/ws" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" 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.5.0" 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/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd | |
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd | |
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.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/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd | |
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd | |
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd"> | |
<!-- the WS consumer configuration --> | |
<ws:consumer-config name="Web_Service_Consumer" wsdlLocation="http://www.webservicex.net/CurrencyConvertor.asmx?WSDL" service="CurrencyConvertor" port="CurrencyConvertorSoap12" serviceAddress="http://www.webservicex.net/CurrencyConvertor.asmx" doc:name="Web Service Consumer"/> | |
<!-- data mapper for the input of the WS-consumer --> | |
<data-mapper:config name="Map_To_Xml_ConversionRate_" transformationGraphPath="map_to_xml_conversionrate_.grf" doc:name="Map_To_Xml_ConversionRate_"/> | |
<!-- map the output of the ws-consumer to JSON --> | |
<data-mapper:config name="Xml_ConversionRateResponse__To_JSON" transformationGraphPath="xml_conversionrateresponse__to_json.grf" doc:name="Xml_ConversionRateResponse__To_JSON"/> | |
<!-- the database module configuration --> | |
<db:generic-config name="Generic_Database_Configuration" url="jdbc:mysql://localhost:3306/test" driverClassName="com.mysql.jdbc.Driver" doc:name="Generic Database Configuration"/> | |
<flow name="mule-configFlow1" doc:name="mule-configFlow1"> | |
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/> | |
<set-payload value="#[['FromCurrency': 'USD', 'ToCurrency' : 'ARS']]" doc:name="Set Payload"/> | |
<data-mapper:transform config-ref="Map_To_Xml_ConversionRate_" doc:name="Map To Xml<ConversionRate>"/> | |
<ws:consumer config-ref="Web_Service_Consumer" operation="ConversionRate" doc:name="Web Service Consumer"/> | |
<data-mapper:transform config-ref="Xml_ConversionRateResponse__To_JSON" doc:name="Xml<ConversionRateResponse> To JSON"/> | |
</flow> | |
<flow name="mule-configFlow2" doc:name="mule-configFlow2"> | |
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/> | |
<request-reply doc:name="Request-Reply"> | |
<vm:outbound-endpoint exchange-pattern="one-way" path="request" doc:name="VM"/> | |
<vm:inbound-endpoint exchange-pattern="one-way" path="reply" doc:name="VM"/> | |
</request-reply> | |
</flow> | |
<flow name="mule-configFlow3" doc:name="mule-configFlow3"> | |
<vm:inbound-endpoint exchange-pattern="one-way" path="request" doc:name="VM"/> | |
<set-payload value="Sample usecase" doc:name="Set Payload"/> | |
</flow> | |
<flow name="mule-configFlow4" doc:name="mule-configFlow4"> | |
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" doc:name="HTTP"/> | |
<scatter-gather doc:name="Scatter-Gather"> | |
<vm:outbound-endpoint exchange-pattern="request-response" path="scatter" doc:name="VM"/> | |
<vm:outbound-endpoint exchange-pattern="request-response" path="scatter" doc:name="VM"/> | |
<vm:outbound-endpoint exchange-pattern="request-response" path="scatter" doc:name="VM"/> | |
</scatter-gather> | |
<json:object-to-json-transformer doc:name="Object to JSON"/> | |
</flow> | |
<flow name="mule-configFlow5" doc:name="mule-configFlow5"> | |
<vm:inbound-endpoint exchange-pattern="request-response" path="scatter" doc:name="VM"/> | |
<logger message="About to wait" level="INFO" doc:name="Logger"/> | |
<expression-component doc:name="Expression"><![CDATA[Thread.sleep(2000)]]></expression-component> | |
<set-payload value="Gather" doc:name="Set Payload"/> | |
</flow> | |
<flow name="mule-configFlow6" doc:name="mule-configFlow6"> | |
<poll doc:name="Poll"> | |
<fixed-frequency-scheduler frequency="30" timeUnit="SECONDS"/> | |
<db:select config-ref="Generic_Database_Configuration" doc:name="Database"> | |
<db:parameterized-query><![CDATA[Select * from test]]></db:parameterized-query> | |
</db:select> | |
</poll> | |
<logger message="#[payload]" level="INFO" doc:name="Logger"/> | |
</flow> | |
</mule> |
Final Words
Studio and Mule 3.5.0 are very promising versions of this integration platform. It has a great deal of features that are not 'visual' but extremely important for our integration architecture, I.E. shared domains, which allows us to split our integration into multiple apps and be able to internally communicate between them.
How to you use a Stored Procedure with a In parameter ?
ReplyDeleteHi,
ReplyDeleteYou wrote "This module allows easy creation of parameterized queries (before these queries were also possible but somehow unnatural to produce), easy access to stored procedures and other interesting features." At the moment we are still using Mule 3.4, I would like to use parameterized queries to prevent SQL injection. Can you point me to somewhere the use of parameterized insert statements is explained? I can't seem to find it in the Mulesoft documentation.
Never mind, I just found out how to do this
ReplyDeletehttp://www.mulesoft.org/documentation-3.2/display/MULE2INTRO/Mule+2.2.7+Feature+Highlights