Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Mule Integration

There are two primary ways you can use MQL inside of Mule.

  1. Transformations - the <mql:transform> element allows you to perform a filter/join/transformation in a flow.

  2. Query service - the <mql:query-service> element easily builds a RESTful service for you from a query

When using MQL inside of Mule, there are several special variables you can use:

Name Description

payload

The current Mule message payload

mule

An object that allows you to do joins using mule endpoints.

Any message property name

Refer to any message property inline. For example, from payload where SomeProperty = 'foo'

To use the Mule integration, be sure to declare the MQL namespace in your Mule config file:


         
      
1
<?xml version="1.0" encoding="UTF-8"?><mule xmlns="http://www.mulesoft.org/schema/mule/core"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:spring="http://www.springframework.org/schema/beans"    xmlns:mql="http://www.mulesoft.org/schema/mule/mql"     xsi:schemaLocation="               http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd http://www.mulesoft.org/schema/mule/mql http://www.mulesoft.org/schema/mule/mql/3.1/mule-mql.xsd

Transformations

The <mql:transform> element allows you to perform a filter/join/transformation in a flow. For example:


         
      
1
<mql:transform query="from payload as p select new { name = p.firstName + ' ' + p.lastName }" />

The <mql:transform> element takes an optional type argument which specifies how you want to process the Mule payload.

Type Description

POJO

The input type is a POJO that requires no transformation

JSON

The input type is JSON and should be transformed into a set of objects MQL can recognize.

AUTO

Auto detect the input type based on the Content-Type header and the data type of the Mule payload. This is the default value.

For example:


         
      
1
<mql:transform type="POJO" query="from payload as p select new { name = p.firstName + ' ' + p.lastName }" />

Query service

The <mql:query-service> element easily builds a Mule service for you on a particular endpoint. With this, you can easily build RESTful JSON services. For example, this will query an object and return the data as JSON:


         
      
1
<mql:query-service   name="Users"    address="http://localhost:9002/users"   query="from userManager.users as user select new { name = user.name, email = user.email, company = sfuser[0].?Company, mobile = sfuser[0].?MobilePhone }"/>

You can also build services which process POJOs:


         
      
1
<mql:query-service   name="Users"    address="vm://users"    type="POJO" query="from userManager.users as user select new { name = user.name, email = user.email, company = sfuser[0].?Company, mobile = sfuser[0].?MobilePhone }"/>

Mule Client

Sometimes, you want to query an endpoint for data within a query. You can do this as part of a from statement or a join. For example, this query will join data from an endpoint:


         
      
1
<flow name="join">    <inbound-endpoint address="vm://join"        exchange-pattern="request-response" />    <mql:transform         query="from payload as p join mule.send('vm://locationService', p.geoIp) as location select new { name = firstName + ' ' + lastName, location = location }" /></flow>

This code will query the vm://locationService endpoint with the property "geoIp" on each object. The result will be stored in the location variable for use in the select statement.