Understand Global Elements
In Mule, a Global Element is a reusable, “master” building block that you configure once, then reference many times from building blocks within multiple flows. Rather than repeatedly writing the same code to apply the same configuration to multiple building blocks, you can create one global element that details your configurations or transport details. Then, you can instruct any number of building blocks across flows in your Mule application to reference that global element.
Some building blocks require 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 building blocks, however, use global elements merely as a matter of convienience and efficiency.
You can acess a global element in Mule Studio via the visual editor or the XML editor.
- 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 (below, left).
- In the XML editor, scroll to the top of the XML config file to see the global elements configured outside and above all flows in the application (below, right).
Creating a Global Element
To create a global element in the visual editor, you can use one of two methods:
- Global Elements Tab— create, edit or delete global elements outside the context of any flow in your application (below, left).
- Click the Global Elements tab at the base of the canvas to navigate to a list of the application’s Global Elements.
- Click the Create button to add a new global element.
- To configure a building block in flow to reference a global element, use the drop-down menu next to the Config Reference field to select a global element from the list of those you have created.
- In a Building Block— create or edit a global element from within a building block in your flow (below, right). This method offers the convenience of creating and referencing global elements in one step as you build your flow.
- Double-click the building block in a flow that you want to reference a global element to open its Pattern Properties panel.
- Nex to the Config Reference field, click the icon to create a new global element, or click the small pencil icon to edit an exiting global element.
- After you have created (or edited), then saved your global element, Studio automatically applies the config reference, and adds the global element to the list of items on the Global Elements tab.
To create a global element in the XML editor, write its configuration code at the top of your XML config file, above — and outside — any flows within your application.
To configure a building block in flow to reference a global element, add a
connector-ref: attribute to the building block.