Tuesday, April 21, 2015

My 10 Minute DB2 App on Bluemix

I needed some fun at the end of the workday today. Why not enhance my own skills, do some "coding", and try out Node-RED on Bluemix again (I performed a "phoney" test in October already). This time, I wanted to see whether a database like DB2 or dashDB is supported as backend.

Node-RED Starter: This application demonstrates how to run the Node-RED open-source project within IBM Bluemix.
Node-RED Starter
Node-RED
storage nodes
To get started I logged into my free trial account on http://bluemix.net. I selected the "Node-RED Starter" from the catalog and created the app skeleton. After the app was staged (the resources allocated, files copied, and the skeleton app started), I could begin wiring up my application logic. My first look on the wiring board went to the list of supported storage nodes. What was new since my last test is support for dashDB and "sqldb" (DB2) as input and output nodes. That is, it is possible to store data in those two database systems (output) and bring data into the app by querying a database (input).

To use DB2 in Node-RED, you need to create a sqldb service in Bluemix first. This meant going back to the catalog, skipping to the Data Management section, selecting the sqldb service, and adding it to my application (see picture below). Thereafter, my application needed to be restaged (restarted), so that it could pick up the properties of the sqldb service.

Adding the sqldb/DB2 service in Bluemix


Now it was time for my coding and SQL skills (or so :). I picked an http input node, a sqldb input node, and an http output node and wired them together:
App wiring in Node-RED
For the http nodes I only changed the name to "Qtime" and "output" and defined the URL for the input ("/currenttime"). My "DB2node" required either hard-coding a query or passing them in. In order to stay within my set 10 minute limit, I just coded up a simple query as shown:

My DB2 code in Node-RED
With the wiring done I pressed the "Deploy" button on my Node-RED screen, then it was time for the QA test. I entered my application URL in the browser and the answer page was seen almost immediately:

Current time from DB2 returned
The current time obtained by querying DB2 was packed into the http response message. What is missing now is some beautification, putting some lipstick on my little pig. But else I am almost ready for starting my own business providing a time service...

BTW: Writing up this blog entry took three times as long as putting the example together and have it up and running. Can you do the same...?



No comments:

LinkWithin

Related Posts with Thumbnails