Contact Us 1-800-596-4880

Global Elements

global In Mule, a Global Element is one that you configure once, then reference many times from elements within multiple flows. Rather than repeatedly writing the same code to apply the same configuration to multiple elements in flows, you can create one global element that details your configurations or transport details. Then, you can instruct any number of elements across flows in your Mule application to reference the global element for specifics on how to behave.

  • Global elements provide flexibility.
    An element can apply a global element’s configuration exactly as defined, or can enhance the global configuration with modifications.

  • Global elements are reusable.
    You can configure a global element just once, then share that configuration among building blocks of the same type. This is particularly useful when you have to define the connection details and login credentials for an external source, such as a SaaS application or database.

  • Global elements offer efficiency.
    Rather than changing the same configuration multiple times within many building blocks, you can change a configuration once, in the “master”, and Studio applies the changes to all that reference it.

Creating a Global Element

The configuration of some elements requires a reference to a global element. For example, some message sources must reference a global connector element in order to function as a transport. The majority of elements, however, use global elements merely as a matter of convenience and efficiency.

STUDIO Visual Editor

  1. In the visual editor, click the Global Elements tab at the base of the canvas to access a list of all global elements in an application.

    globalTab
  2. Click the Create button to add a new global element.

  3. In the Choose Global Type wizard, navigate the directories or use the filter to select the type of global element you wish to create, then click OK.

    chooseType
  4. Define the configurable parameters of your global element, then click OK to save.

  5. To configure a local element in flow to reference a global element, use the drop-down menu next to the Config Reference field to select a global element from a list of those you have created.

    configRef

You can create a new global element from within a local element in your flow.

Click the plus icon next to the Config Reference field, then follow the steps above to configure a global element. Click the edit icon to edit an existing global element.

createWithin

XML Editor or Standalone

  1. In the XML Editor in Studio, or in your XML config file, create a global element above and outside any flows within your application.

  2. Define the values of attributes associated with the type of global element you added (see Examples below).

  3. To configure an element in flow to reference a global element, add a config-ref or connector-ref attribute to the element. The example below includes a global Salesforce element (sfdc:config), and a flow which includes a Salesforce connector (sfdc:create) that references the global Salesforce element.

    <?xml version="1.0" encoding="UTF-8"?>
    
    <mule xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:file="http://www.mulesoft.org/schema/mule/file" 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.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.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/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    
        <sfdc:config name="Salesforce1" username="username" password="password"  doc:name="Salesforce" securityToken="IQZjCdweSF45JD90Me2BWKVDo">
            <sfdc:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
        </sfdc:config>
    
        <flow name="Contacts_to_SFDC" doc:name="Contacts_to_SFDC">
            ...
            <sfdc:create config-ref="Salesforce1" type="" doc:name="Salesforce Connector">
                <sfdc:objects ref="#[payload]"/>
            </sfdc:create>
        </flow>
    
    </mule>

Examples

HTTP Connector

<?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" 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="myNewProjectFlow1" doc:name="myNewProjectFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" connector-ref="HTTP_Connector"/>
    </flow>

</mule>

JDBC Connector

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" 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/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd">

    <jdbc-ee:mysql-data-source name="MySQL_Data_Source" user="test" password="test" url="jdbc:mysql://localhost:3306/[dbName]" transactionIsolation="UNSPECIFIED" doc:name="MySQL Data Source"/>

    <jdbc-ee:connector name="Database_Connector" dataSource-ref="MySQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>

    <flow name="myNewProjectFlow1" doc:name="myNewProjectFlow1">
        <jdbc-ee:inbound-endpoint queryKey="test" queryTimeout="-1" pollingFrequency="1000" connector-ref="Database_Connector" doc:name="Database">
            <jdbc-ee:query key="test" value="test"/>
        </jdbc-ee:inbound-endpoint>
    </flow>

</mule>

JMS Connector

<?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>

See Also