App Connect

 View Only
Expand all | Collapse all

EnvironmentVariables: in server.conf.yaml file

  • 1.  EnvironmentVariables: in server.conf.yaml file

    Posted Wed September 13, 2023 05:56 AM

    Hi Team,

    How to access the EnvironmentVariables: from server.conf.yaml file into esql.



    ------------------------------
    RAVI TEJA KATRAGADDA
    ------------------------------


  • 2.  RE: EnvironmentVariables: in server.conf.yaml file

    IBM Champion
    Posted Fri September 15, 2023 07:38 AM

    Hi Ravi

    You can get whatever you want from a java compute node, there you can just request environment variables with the standard java api

    String value_name = System.getEnv(key_of_variable);

    Depending on your use case,  you can also access them on the mqinput node

    the "encodedvar" being the name of the variable you want to use there.



    ------------------------------
    Regards
    Matthias Blomme
    ------------------------------



  • 3.  RE: EnvironmentVariables: in server.conf.yaml file

    Posted Fri September 15, 2023 10:04 AM

    what is the Xpath used in Esql for accessing the below section variable (EnvironmentVariables:) from the server.conf.yaml from the execution group , attached below screen shot 

    EnvironmentVariables:
      ENV_VAR_ONE: 'env_var_one_value'    --> How to access this variable in Esql or what is the usecase in the server.conf.yaml



    ------------------------------
    RAVI TEJA KATRAGADDA
    ------------------------------



  • 4.  RE: EnvironmentVariables: in server.conf.yaml file

    Posted Mon September 18, 2023 02:37 AM

    Hi Ravi

    I don't beleive it is meant to be used that way. Have a look here: https://www.ibm.com/docs/en/app-connect/12.0?topic=servers-configuring-independent-integration-server-startup-script

    As you can see from my screenshot in the previous post, you can access them from the mqinput node.

    If you want to access env variables from anywhere in your flow you can always create a java function

    public class ReadEnvVar_ReadEnvVar {
     public static String getVar(String varName) {
    return System.getenv(varName);
    }
    }

    And an esql function that point to that java function

    CREATE FUNCTION readEnvVar(IN varName CHARACTER)
        RETURNS CHARACTER
        LANGUAGE JAVA
        EXTERNAL NAME "ReadEnvVar_ReadEnvVar.getVar";

    So you can use it anywhere in esql like so

    CREATE FUNCTION Main() RETURNS BOOLEAN
        BEGIN
            CALL CopyEntireMessage();
            SET OutputRoot.JSON.Data.Result = readEnvVar(InputRoot.JSON.Data.Request);
            RETURN TRUE;
        END;

    It works for any env var specified in your server.conf.yaml



    ------------------------------
    Matthias Blomme
    ------------------------------



  • 5.  RE: EnvironmentVariables: in server.conf.yaml file

    Posted Tue September 19, 2023 03:57 AM

    Thanks Matthias Blomme



    ------------------------------
    RAVI TEJA KATRAGADDA
    ------------------------------



  • 6.  RE: EnvironmentVariables: in server.conf.yaml file

    Posted Wed September 20, 2023 04:09 PM

    It's also possible to read user variables from ESQL, and have the user variable set to an environment variable. This requires two steps, with the first being in server.conf.yaml:

    UserVariables:
      envVarUserVariable: '${ENV_VAR_ONE}'
    resolveUserVariableEnvVars: true

    and the second in ESQL:

    DECLARE envVarUserVariable EXTERNAL CHARACTER;

    See https://github.com/trevor-dolby-at-ibm-com/ace-esql-read-env-var for code that shows this working for ACE 12.0.4 and above.



    ------------------------------
    Trevor Dolby
    IBM Expert Labs
    ------------------------------



  • 7.  RE: EnvironmentVariables: in server.conf.yaml file

    Posted Wed September 20, 2023 04:10 PM

    Note also that you can call Java's System.getenv directly, and no intermediate code is needed:

    CREATE FUNCTION javaLangSystemGetenv( IN name CHARACTER )
      RETURNS CHARACTER
      LANGUAGE JAVA
      EXTERNAL NAME "java.lang.System.getenv";

    and that is also shown in the repo linked above.



    ------------------------------
    Trevor Dolby
    IBM Expert Labs
    ------------------------------



  • 8.  RE: EnvironmentVariables: in server.conf.yaml file

    Posted Wed September 20, 2023 09:29 AM

    Any document shows that how the environment variable being used in the node properties like this way?



    ------------------------------
    Davis Chan
    Thornhill ON
    416-3999320
    ------------------------------



  • 9.  RE: EnvironmentVariables: in server.conf.yaml file

    Posted Wed September 20, 2023 04:07 PM

    I think Ben Thompson first mentioned it at Explore the new features in App Connect Enterprise 12.0.5.0 (ibm.com) and I use the same idea in a few places in the https://github.com/trevor-dolby-at-ibm-com/ace-http-mq-request-reply demo repo for the Scaling ACE integrations that use MQ request/reply (ibm.com) blog post.

    Hope that helps!



    ------------------------------
    Trevor Dolby
    IBM Expert Labs
    ------------------------------