Contact Us 1-800-596-4880

Understanding Global Elements

In Mule terms, 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.

Why Use Global Elements

Some building blocks, such as most Anypoint Connectors, 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 convenience and efficiency.

A global element could be referenced by any number of relevant "building blocks", represented by the gray boxes in the image below.

global_relationship

flexible2

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.

reusable

Global elements are reusable.
You can configure a global element just once, then share that configuration among building blocks of the same type.

efficient

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.

Accessing Global Elements

You can access a global element in Mule Studio via the visual editor or the XML editor.

  • In the Anypoint Studio 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 Anypoint Studio XML Editor, scroll to the top of the XML configuration file to see the global elements configured in the project. Find these XML lines corresponding to the global elements in the project outside of and above all flows defined in the application (below, right).

global_visual_XML

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).

    1. Click the Global Elements tab at the base of the canvas to navigate to a list of the application’s Global Elements.

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

    3. 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.

    1. Double-click the building block in a flow that you want to reference a global element in order to open its Pattern Properties panel.

    2. Next to the Config Reference field, click the (plus) icon to create a new global element, or click the small pencil icon to edit an exiting global element.

    3. After you have created (or edited), and 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.

create_global

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.