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.
Global elements provide flexibility. A building block 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. |
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. |
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
Visual Editor
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 Propertiespanel.
- 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.
XML Editor
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 config-ref:
or connector-ref:
attribute to the building block.