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

Mule Query Language

MQL is a LINQ inspired query lanaguage for Java and Mule. With it you can filter, join and transform data from Mule messages, cloud connectors, and Spring beans in very concise code. And with the <mql:query-service> support inside Mule, you can instantly turn that query into a REST service. MQL is currently in beta.

Here are some quick samples:

Description Query

Filter Data

from userManager.users   where division = ‘Sales’ and     (email like ‘’ or email like ‘’)

Queries userManager.getUsers() and returns all users which are in Sales and have an email which contains "" or ""

Transform data into a Map/POJO

from userManager.users as u select new {  href = 'http://localhost/users/' +,  name = u.firstName + ' ' + u.lastName,  division = u.division}

Queries userManager.getUsers() and creates new objects which have the href, name and division properties. This object will be a Map by default, but can also be a POJO by using syntax like new( in the select statement.

Join data from Salesforce

from userManager.users as user  join salesforce.query('SELECT Company, MobilePhone                          FROM Lead                          WHERE Email = \'' + + '\'', 1)    as sfuser  select new {    name =,    email =,    company = sfuser[0].?Company,    mobilePhone = sfuser[0].?MobilePhone  }

Queries userManager.getUsers() and for each user calls the SalesForce cloud connector to retrieve user information based on the users’s email address. In the select statement, we’re creating a new object based on both the local data (name and email) and the SalesForce data (company and mobile phone).

Instant REST service

<mql:query-service name="UsersService"   address="http://localhost:9002/mulesoft-users"  query="from userManager.users as u where email like ''"/>

Creates a REST services on the specified address which executes the specified query. Data is returned in JSON format.

Transform Mule messages

<mql:transform query="select new { name =, email =}"/>

Takes a Mule message payload (POJO or JSON data) and transforms it into a new object (POJO or JSON). If the payload is a Collection, it will transform each individual object. If the payload is a single object, it will return a single transformed object.

Use Cases

Name Description

Query Java Objects

Query local POJOs and transform them into different objects.

Merging Datasets

In this example, see how you can take activity streams from Twitter and Yammer and merge them into a common format.

Enrich Data

In this example, local data is enriched with data from SalesForce

Service Versioning

Easily handle two different data formats (version 1.0 and version 2.0) for your service.

In this topic: