Combining Services in Bluemix
Bluemix has a set of services that can be combined in a single web application (e.g., output of one service will serve as input of another service).
In this tutorial you will learn how to combine services in IBM Bluemix.
Prerequisite:
You are required to do the Creating a Web Application using Gradle Tutorial.
- The steps used in this tutorial is based from Creating a Web Application using Gradle Tutorial.
You are not required (but recommended) to do the Bluemix Basics Tutorial.
- However, ensure that you have a Bluemix account.
- Your account should have the space
dev
under the regionUS-South
. The creation of the spacedev
is discussed in Bluemix Basics Tutorial.- Make sure that the
cf
tool is installed. The installation ofcf
tool is discussed in Bluemix Basics Tutorial.You are not required (but recommended) to do the GitHub Basics Tutorial.
- However, ensure that you have a GitHub account.
Copy Sample Codes from Git repository
Open a terminal window and create the directory
gradletemp
in the root directory. Go to the created directory.> mkdir bluemixtemp > cd bluemixtemp
Clone the git repository
https://github.com/pong-pantola/bluemix-combined-services.git
and go to the createdbluemix-combined-services
directory.> git clone https://github.com/pong-pantola/bluemix-combined-services.git > cd bluemix-combined-services
Assemble the Gradle project.
Make sure that you are in the
bluemix-combined-services
directory before issuing the command below.> gradle assemble
Output:
:compileJava :processResources :classes :war :assemble BUILD SUCCESSFUL Total time: 9.289 secs
Deploy the Web Application in Bluemix
Login to your Bluemix account using the
cf
tool.Make sure that you are in the
bluemix-combined-services
directory before issuing the command below.> cf login -a https://api.ng.bluemix.net -s dev
Upload the web application to your Bluemix account.
> cf push combination-<your_name> -m 512M -p build/libs/webapp.war
Example:
> cf push combination-pong -m 512M -p build/libs/webapp.war
Add Bluemix Services to the Web Application
Open a web browser and login to your Bluemix account.
Click the widget of your application (
combination-<your_name>
) to see its overview.Click the
ADD A SERVICE OR API
link. You will be redirected to theCatalog
page.Look for the
AlchemyAPI
service and click it.In the
Service name
text box, use the default name.Click the
CREATE
button.When asked to restage your application, click the
CANCEL
button.If you click the
RESTAGE
button, your application will restart. It is advisable to click theRESTAGE
button once you have added all the services, otherwise your web application will keep on restarting every time you clickRESTAGE
which will make the procedure of adding services longer.Repeat the steps above to add the following services:
- Language Translation
- Speech To Text
- Text To Speech
- Cloudant NoSQL DB
- Object Storage
- mongodb (not MongoDB by Compose)
- redis (not Redis by Compose)
VERY IMPORTANT:
For monogdb and redis, as mentioned above, do not use the version "by Compose". Instead, in the
Catalog
page, scroll down in theCATALOG
page until you see theBluemix Labs Catalog
link. Click this link. Look for the services namedmongodb
andredis
.When you add the last service (redis), you will be asked to restage your application, click the
RESTAGE
button. If you don't click theRESTAGE
button, your application will not restart and it will not recognize all the services you added.Wait for your application to restart.
On another browser tab, go to
http://combination-<your_name>.mybluemix.net
.Output:
Alchemy-Cloudant Alchemy-MongoDB Alchemy-Redis Alchemy-TextToSpeech LanguageTranslation-TextToSpeech ObjectStorage-SpeechToText TextToSpeech-ObjectStorage
You have successfully deployed the web application in Bluemix.
Test the Application
Each hyperlink demonstrates how two services are combined. For example, the link Alchemy-Cloudant
demonstrates how the output of Alchemy API is used in Cloudant NoSQL DB.
Alchemy-Cloudant
This asks a user to enter a URL of an image file. The image should contain at least one person. Alchemy API will extract information from the image. Specifically, it will extract the age and gender of the person in the image.
The extracted age and gender are saved in a Cloudant NoSQL DB service.
Alchemy-MongoDB
This is the same as Alchemy-Cloudant except that the extracted age and gender are saved in a mongodb service .
Alchemy-Redis
This is the same as Alchemy-Cloudant and Alchemy-MongoDB except that the extracted age and gender are saved in a redis service .
Alchemy-TextToSpeech
This is the same as Alchemy-Cloudant, Alchemy-MongoDB, and Alchemy-Redis. However, instead of saving the age and gender, it will create a WAV file that contains the following sound:
Information Extraction Complete. The person in the picture is a <GENDER>. <His/Her> age is <AGE>
.LanguageTranslation-TextToSpeech
This asks a user to enter a text in Spanish. Using the Language Translation service, it will convert the text to English. The English text is converted to a speech (i.e., WAV file) using the Text To Speech Service.
ObjectStorage-SpeechToText
This asks a user to select a WAV file containing an English sentence. The WAV file is uploaded in an Object Storage service.
From the Object Storage service, it will download the WAV file and convert it to its equivalent to text using the Speech To Text service.
TextToSpeech-ObjectStorage
This asks a user to enter a text. The text is converted to speech (i.e., WAV file) using the Text To Speech service. The WAV file is uploaded in an Object Storage service.
Clean up
Delete your Bluemix application
combination-<your_name>
.Make sure to delete as well all the created services.
End of Tutorial
Go back to the List of Tutorials.