4

We have global Variable concept in TIBCO where do we have the same concept in Mulesoft ?

Like setting a Global Variable so that during the run time or deployment based on environment. Is there any similar case in Mulesoft

Vignesh
  • 1,183
  • 2
  • 10
  • 18

5 Answers5

5

There are global-properties that can be set per mule app and also environment variables that can be set to override and set environment-specific properties. These can be configured individually or environment variables can be set to load specific property files per environment. All info is in the documentation here: https://docs.mulesoft.com/mule-runtime/4.2/configuring-properties

Ryan Carter
  • 11,441
  • 2
  • 20
  • 27
4

For every Mule app, there are global properties that can be configured accordingly. In Mule 4 as they call it "Property placeholder" values of which can be made available in variety of ways. so we can use global property syntax to reference .yaml or .properties files and create new global properties that depend on the configuration properties.

for more info refer to

Abhilash
  • 41
  • 2
1

If it is global variables you are asking? Then it has more to do with mule 3. In Mule 3 we have a session, local, global variables to work with, based on the scope of use. In mule 4 there is no concept of global and local variables. All variables declared in mule 4 are having global scope. This means you can access it across all flows, sub-flows, XML files. Note: The scope of the Mule message payload is not global.

All the other answers talk about property parameterization using property placeholder (mule 3 concept) and global configurations in global elements.

I believe you must change this question. Don't call the values you pass in runtime as "Global Variables". Global Variables is an entirely different concept.

Anurag Sharma
  • 780
  • 7
  • 31
Thinker-101
  • 554
  • 5
  • 19
  • I believe the answers given are correct for the OP question. The pure concept of "Global Variable" as in computer science is not highly relevant in a mule app. Sometimes as we move to serverless compute, and microservices, we do not find a place for concepts from an older programming model. – agentv Oct 15 '20 at 16:54
  • 1
    Hmm, or we could just call them as global property or a global runtime argument/system args. I called it out since Mule 3 has this segregation of variables into 3 categories. But still, I consider all other answers are relevant to the ask. Once again, global and local variables are also part of `do` scopes used within dataweave. I am just mentioning it for anyone who comes to this page blindly by seeing the title. It helps. – Thinker-101 Oct 16 '20 at 05:39
0

Mule 4 has carried over the legacy of global Variables or in few general terms referred as “Property Placeholders” from earlier Runtime versions:

This aspect of Mule ESB is used for mainly placing values to environment specific variables and in frequent cases to maintain abstraction and security: Property Placeholders:

<smtp:outbound-endpoint user="${smtp.username}" password="${smtp.password}"/>

Global Properties:

<global-property name="smtp.host" value="smtp.mail.com"/>
<global-property name="smtp.subject" value="Subject of Email"/>

Properties files:

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

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

<context:property-placeholder location="smtp.properties"/>

<flow name="myProject_flow1">
    <logger message="${propertyFromFile}" doc:name="System Property Set in Property File"/>
</flow>

To hold multiple properties file:

<context:property-placeholder location="email.properties,http.properties,system.properties"/>

Message Properties:

#[message.inboundProperties['Content-Type']]

System Properties Environment Variables from OS or in General case: General: ${variableName} From OS: <logger message="${USER}" doc:name="Environment Property Set in OS" />

Properties of globally referenced variables in cloud hub: Log in to your Anypoint Platform account. 1. Go to CloudHub. 2. Either click Deploy Application to deploy a new application, or select a running application and click Manage Application. 3. Select the Properties tab in the Settings section.

Reference: https://docs.mulesoft.com/mule-runtime/{Runtime-version}/configuring-properties

SDE
  • 85
  • 1
  • 13
0

In Mulesoft we call this runtime variable. we create some files in Mulesoft called properties files, that are environment-specific.for example

if we are deploying our Mulesoft API on the dev environment then create a file with the name "dev.properties". Add all properties in this file that we need at deployment times below

api.host=abc api.port=8081

now in your main interface add a global configuration to read this file as below#

<configuration-properties
        doc:name="env file properties configuration"
        doc:id="010e36f9-1ef3-4104-b42f-21d2d4012ef7"
        file="properties/${mule_env}.properties"
        doc:description="Global configuration to specify environmnet property files" />

here mule_env=environment name as here its dev will get read from your API deployment process (with the help of dev-ops you can set it in scripts)

Anurag Sharma
  • 780
  • 7
  • 31