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

Mule Connectors

connector-1 Anypoint Connectors receive or send messages between Mule and one or more external sources, such as files, databases, or Web services. Connectors can act as message sources by working as inbound endpoints, they can act as a message processor that performs an operation in middle of a flow, or they can fall at the end of a flow and act as the recipient of the final payload data. 

Connectors in Mule are either endpoint-based* or *operation-based. Endpoint-based connectors follow either a one-way or request-response exchange pattern and are often (but not always) named and based around a standard data communication protocol, such as HTTP, FTP, JMS, and SMTP. Operation-based connectors follow an information exchange pattern based on the operation that you select and are often (but not always) named and based around one or more specific third-party APIs.

Endpoint-Based Connectors

Endpoint based connectors are configured as either inbound or outbound endpoints in a flow. Inbound endpoints serve as a message source for a flow. Outbound endpoints can occur mid-flow or at the end of flows, and send information to external systems. 

endpointbased

Operation-Based Connectors

Most connectors that are not based on a standard communication protocol are operation-based, which means that when you add the connector to your flow, you immediately define a specific operation for that connector to perform.

operationbased

The XML element of the connector differs according to the operation that you select, taking the form <connectorName>:<operation>. For example, sfdc:query or sfdc:upsert-bulk. The remaining configuration attributes or child elements are determined by the operation that you select.

Global Connector Configuration

Some connectors require that connection information such as username, password, and security tokens be configured in a global element rather than at the level of the message processor within the flow. Many connectors of the same type in one application can reference the connector configuration at the global level. For operation-based connectors, the global connector configuration is mandatory, but for most endpoint-based connectors it is optional. 

Note that the global element that you configure in Anypoint Studio is called a Connector Configuration. The corresponding XML tags are <connectorName>:config for operation-based connectors and <connectorName>:connector for endpoint-based connectors. See the examples below.

Examples

HTTP Connector

This example shows how an HTTP connector, which is endpoint-based, can be configured as an inbound and outbound endpoint in a flow. In this example, the HTTP connector does not require a global connector configuration, but you can still define one to globally specify optional connection attributes.


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" 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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
 
    <http:connector name="HTTP_connector_configuration" enableCookies="true" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTP-HTTPS">
        <reconnect/>
    </http:connector>
 
    <flow name="httpexampleFlow1" doc:name="httpexampleFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" connector-ref="HTTP_connector_configuration" doc:name="HTTP"/>
        <set-payload value="foo" doc:name="Set Payload"/>
        <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" connector-ref="HTTP_connector_configuration" method="POST" doc:name="HTTP"/>
    </flow>
 
</mule>

JMS Connector

This example shows a JMS connector, which is also endpoint-based, configured as an inbound endpoint in a flow. The JMS endpoint includes a mandatory reference to a global connector configuration which contains the connection parameters.


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="UTF-8"?>
 
<mule xmlns:jms="http://www.mulesoft.org/schema/mule/jms" 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/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd">
 
    <jms:activemq-connector name="Active_MQ" username="test" password="test" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
 
    <flow name="myNewProjectFlow1" doc:name="myNewProjectFlow1">
        <jms:inbound-endpoint queue="test" connector-ref="Active_MQ" doc:name="JMS Endpoint"/>
 
...
    </flow>
 
</mule>

Salesforce Connector

This example shows a Salesforce connector, which is operation-based, configured to create a new contact in Salesforce based on the payload pulled from a file endpoint. The Salesforce connector includes a mandatory reference to a global connector configuration which contains the connection parameters.


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="UTF-8"?>
 
<mule xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:file="http://www.mulesoft.org/schema/mule/file"
    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.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
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/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd">
 
    <sfdc:config name="Salesforce" username="test" password="test" securityToken="test" doc:name="Salesforce"/>
 
    <flow name="newprojectFlow1" doc:name="newprojectFlow1">
        <file:inbound-endpoint responseTimeout="10000" doc:name="File" path="/Users/AaronMacbook/Desktop/Input"/>
        <sfdc:create config-ref="Salesforce" type="contact" doc:name="Salesforce">
            <sfdc:objects ref="#[payload]"/>
        </sfdc:create>
 
    </flow>
 
</mule>

See Also