Using the Application Configuration Repository to save credentials

 View Only

Using the Application Configuration Repository to save credentials 

Thu September 24, 2020 12:44 PM

Whenever you use a Streams operator to connect to an external system such as RabbitMQ, IBM Event Streams, or IBM Cloud Object Storage, you have to provide the credentials to the operator. Instead of doing so for every application, you can save the credentials in the Streams Console secure configuration repository. The saved credentials are called application configurations.

Application configurations are stored securely in a Streams instance.


After saving the credentials in an application configuration, any operator or application that needs those credentials can then retrieve the saved configuration information from the repository as needed, for example when connecting to the external service or at operator initialization time.

Advantages of using application configurations

  • Code is easier to read since you just specify the name of the credentials object.
  • No need to repeatedly copy and save the credentials, they're saved once
  • No risk of accidentally checking in the credentials with the source code

This article will demonstrate how to create and make use of use an application configuration object to store authentication information used to connect to a RabbitMQ server to process messages for a Streams application.

Using application configurations

The basic steps are:
  1. Create the configuration object in the Streams Console.
  2. Use the configuration object in your code:
    1.  Option 1: After you create the application configuration, you can use these functions to access their values from your SPL, Python or Java application.  
      SPL Functions: getApplicationConfigurationProperty or getApplicationConfiguration
      Java functions: getApplicationConfiguration
      Python function: streamsx.ec.get_application_configuration
    2. Option 2:  The other way to use an application configuration is with existing operators that support specifying credentials using a configuration object. You specify the name of the application object to the operator and it will retreive the information and use it to connect to your data source. The toolkits for connecting to RabbitMQ, IBM Event Streanms, Kakfa, and Cloud Object Storage all support this mechanis.
In this article, I'll demonstrate how to use an application configuration object with the RabbitMQ toolkit.

Listed below are the steps I’ll demonstrate showing how application configuration objects can be used in a Streams environment:

  • Using the Streams Console, create an application configuration object containing the connection credentials for a RabbitMQ server.
  • Modify the RabbitMQSample.spl sample file to get the RabbitMQ connection information from the application configuration object we just created.
  • Launch the RabbitMQSample application in showing the flow of messages from the Streams application through the RabbitMQ server using the connection credentials in the application configuration object.

Streams Console: Creating the Application Configuration object

  • Launch the Streams Console. From the Application Dashboard,
  • Hover over the left most button in the menu bar, select the instance and click on the link called ‘Manage Application Configurations’.

For Streams v4.3,

  • You will see two tabs on the Application Configuration page. Make sure the tab called Application Configuration is selected. At the top of the page is a dropdown labeled ‘Scope’. If you have domain permissions this will be set to domain, if you have permissions on any instances in the domain, the drop down will also contain those instance names.
  • For this example we can either create an Application Configuration at the domain level, or at the instance level.
  • I will select an instance called rabbitInstance I created earlier.
    Next, select the ‘+’ button which launches the New application configuration dialog.

For Streams v5+, simply click the + button to add a new configuration.




Type in a name for the application configuration, RabbitMQAppConfig, give it a description if you like and then add the following in the ‘Name’ and ‘Value’ fields. You will need to do this twice, once for each property.

Name: Value:
username <your RabbitMQ user>
password <your RabbitMQ user’s password>

If you would like to save this information into a plain text properties file in case you want to upload it later to create another application configuration, toggle the checkbox called ‘Create a properties file from the application configuration’.

Now click ‘Save App Config’.



The tabbed area Application Configuration now shows the new application configuration object. To copy, edit, remove it, or to create a properties file for all the name/value pairs in the object select the gear icon in the upper right corner of the object to access these menu options.


Modifying RabbitMQSample.spl to use the Application Configuration object

To demonstrate how to use the newly created application configuration, we'll use the RabbitMQSample included in the RabbitMQ toolkit. The RabbitMQSample we will modify is here. Clone the repository and import it into Streams Studio or Microsoft Visual Studio Code.

Modifying the application for your environment

Import the RabbitMQSample into your workspace.
Open the samples/RabbitMQSample/com.ibm.streamsx.rabbitmq.sample/RabbitMQSample.spl file. If you are using Streams Studio, make sure to open with the SPL editor by clicking the file and choosing Open With > SPL Editor.

Modify the application by changing the following parameters for your environment:

$hostAndPort : "<your_rabbit_mq_server>:port";

After making the change build the example.

Launching the application

Now let's launch the application and view the output.

If using VS Code,
  • Right click on the SPL file and choose Build and Submit Job.
  • When the build is complete, accept the defaults and submit the job.
  • From the Streams Explorer pane, expand the instance, find the job, and click the "download logs" button.


If using Streams Studio:

  • Right click on the RabbitMQSample [Build: BuildConfig] object and select ‘Launch… Launch Active Build Config to Running Instance.’ Accept the default values and click the ‘Launch’ button.
  • Now go to the Streams Explorer view, select the Streams Jobs item and expand it to see your running job.
  • Right click the job and select ‘Show Instance Graph’.
  • Once the Instance Graph appears right click the ‘SinkOp’ operator and select ‘Show Log’, then ‘Show PE Console’.

The output should look similar to the below:

"Message: {message=\"What is friendship and why do we need it?\",routing_key=\"What is reality?\"}"
"Message: {message=\"What is friendship and why do we need it?\",routing_key=\"What is reality?\"}"
"Message: {message=\"What is friendship and why do we need it?\",routing_key=\"What is reality?\"}"
"Message: {message=\"What is friendship and why do we need it?\",routing_key=\"What is reality?\"}"
"Message: {message=\"What is friendship and why do we need it?\",routing_key=\"What is reality?\"}"
"Message: {message=\"What is friendship and why do we need it?\",routing_key=\"What is reality?\"}"

If it does not, check the console tab for errors in Streams Studio and the Output pane for errors in VS Code.

It is possible your RabbitMQ server does not have a default username and password set up for connections. Make sure you have the example working correctly here before going to the next section that uses the application configuration we created earlier.
Check your RabbitMQ server configuration if you can not connect properly to RabbitMQ at this point. You may need to add the username and password parameters to the RabbitMQSample.spl file.

Modifying the application to use the Application Configuration Object

In the editor, add the following parameters in addition to those present under the param clause. If you named the application configuration object you created something other than “RabbitMQAppConfig” change it to the appropriate name.

expression<rstring> $userPropName : "username";
expression<rstring> $passwordPropName: "password";
expression<rstring> $appConfigName: "RabbitMQAppConfig";

Now build the application, and launch it again.

Check for any errors. If there are none, look at the ‘Console PE log’ of the ‘SinkOp’ and verify the messages are being received from the MQServer.

If there are errors check the following:

  • You added the above params to the RabbitMQSample.spl file.
  • The appConfigName parameter points to the correct application configuration name.
  • If you created the application configuration at the instance scope, make sure you are launching the SPL application to the proper instance. Make sure the instance is running.

Summary

This article explained and showed the following:

  • Streams Console: How to create an application configuration object containing RabbitMQ server connection information
  • Streams Studio/VS Code:
    • How to modify an SPL Application to use the Application Configuration object created
    • How to launch an SPL application to a running instance and verify the RabbitMQ messages are being output

References

Use these functions to access the an application configuration from your Streams application:
SPL Functions: getApplicationConfigurationProperty or getApplicationConfiguration
Java functions: getApplicationConfiguration
Python function: streamsx.ec.get_application_configuration
#CloudPakforDataGroup

Statistics

0 Favorited
8 Views
0 Files
0 Shares
0 Downloads