Search code examples
configuration-filesmule-studioanypoint-studiodataweave

Defining various DB & Salesforce access information in Mule Anypoint Studio


I am running Mule Anypoint studio v6.2.4 under Windows. I have an application which gets data records from a SQL Server DB and populates them into Salesforce Org. The application was developed using examples and works fine in the current scenario of one DB and one SF parameters defined in mule.{mule.env}.properties file.

Now I need to access a different DB for input records and populate them to a different Salesforce org. Changing the access parameters in properties file every time is tedious and error prone. (e.g. 4 DB's & 4 SF Orgs}

What I would like to do is define access parameters (for various SQL Server DB and Salesforce Orgs), specify DbName and SFName as http query parameters, and let mule application pick the correct parameters for connection.

How would I accomplish it? Details will help me as I am not that proficient in Mule yet.

Thanks

Kishore


Solution

  • You could create one property file with a full list of the database connections:

    #DB of puppies
    postgres.puppies.user=mule
    postgres.puppies.password=password
    postgres.puppies.host=db-1
    postgres.puppies.db=mule-puppies
    
    #DB of cars
    postgres.cars.user=mule
    postgres.cars.password=password
    postgres.cars.host=db-2
    postgres.cars.db=mule-cars
    

    UPDATED

    Then, if yout want to read a query parameter from the dataweave component loading one of your Properties:

    %dw 1.0
    %output application/java
    ---
    p("postgres." ++ inboundProperties."http.query.params"['db-name'] ++ ".user")
    

    Note: Consider when QueryParameter.db-name is null you will get an exception (you should handle this exception), or, another way to do it, is by handling nulls from your own data-weave (https://forums.mulesoft.com/questions/28105/how-do-i-do-a-null-check-in-dataweave.html), e.g. when null you could define a default database

    Hope this helps clarifying