Welcome!

Cloud Expo Authors: Tom Flynn, Stephen Pierzchala, Jason Bloomberg, Elizabeth White, Jeremy Geelan

Related Topics: Cloud Expo, Java, SOA & WOA, Open Source, Virtualization, Web 2.0

Cloud Expo: Tutorial

Scalable Chat Room App in 15 Minutes

VMware’s WaveMaker + PubNub + Cloud Foundry

WaveMaker, acquired by VMware in March 2011, is a free, open source rapid application development environment for building, maintaining and modernizing business-critical Web 2.0 applications.

PubNub, a privately held company, is a fast real-time Infrastructure-as-a-Service for building real-time web and mobile apps.

Cloud Foundry is an open Platform-as-a-Service, providing a choice of clouds, developer frameworks and application services. Initiated by VMware, with broad industry support, Cloud Foundry makes it faster and easier to build, test, deploy and scale applications. It is an open source project and is available through a variety of private cloud distributions and public cloud instances, including CloudFoundry.com.

Introduction
I've been using WaveMaker since I started working at the startup in 2008 and it has been a great IDE for quickly creating robust enterprise AJAX Web applications integrating SQL databases, and SOAP/REST Web Services. Along came Cloud Foundry and deploying those applications on a scalable platform became just as quick and easy as WaveMaker made it to build them. Add PubNub to the equation and you get the power of real time messaging in an instant. No complicated servers to configure and no expertise required to start using the service - just a few lines of code to start sending and receiving messages.

In this tutorial I will walk you through how to build and deploy a basic chat room application in under 15 minutes using PubNub, WaveMaker, and Cloud Foundry. You can deploy to whatever application server platform you like, however, in this tutorial, we are going full-cloud so there will be no installation required. WaveMaker Studio runs in Cloud Foundry, PubNub's messaging service is cloud-hosted, and we'll be deploying to Cloud Foundry, so no need to install an app server either.

Here is what you will need:

A Free Cloud Foundry account: https://my.cloudfoundry.com/signup
At the link above, you can request a new Cloud Foundry account and confirmation email is sent. Remember your account login because you will need it when you deploy your app to Cloud Foundry from WaveMaker.

WaveMaker 6.5 Installed: http://wavemaker.com/downloads/
The latest version of WaveMaker installer is available at the the above link.

A Free PubNub account: http://www.pubnub.com/
Note: you actually don't need this because we will just be using the demo keys, but you will want one by the time you finish this tutorial.

Let's get started - hit the start button on your stopwatch...

Project Setup
1. Create a new project in WaveMaker named quickchat

2. In a text editor, open the index.html file of your project
(look in <wavemaker_install_dir>/projects/quickchat/webapproot)
and add the following div and script elements immediately following the the script tag containing "project.a.js" (if you use your own keys, just replace demo with your "pub" and "sub" keys provided to you):
<div pub-key="demo" sub-key="demo" ssl="off" origin="pubsub.pubnub.com" id="pubnub"></div>
<script src="http://pubnub.s3.amazonaws.com/pubnub-3.3.min.js"></script>

3. Save the file and close.

Create the User Interface
Back in WaveMaker, add UI widgets (DnD from the palette to the canvas) to your Main page and configure as follows (expand the "Editors" node on the palette):

1. Text Area
name: taChat
caption: Chat Messages
readonly: checked

2. Text
name: tfMessage
caption: Message

3. Button (top of the palette)
name: btSend
caption: Send

Feel free to make this UI as pretty as you like, but hit the pause button on your stop watch - this is not part of the "get 'er done in under 15 minutes" promise I made. The focus is on a basic chat app - nothing fancy.

Add a Dash of PubNub
Now it's time to write a little code - and I mean a little.

  1. Select the btSend button
  2. Open the "Events" section of the property panel
  3. To send (publish) messages to a channel, we need to add the PUBNUB.publish method in the btSelect button's onclick event. Select "JavaScript Event" for the "onclick" event:


... this will open the page's source editor with the cursor ready to add some code in the btSendClick event. Now add the following code:

PUBNUB.publish({
channel: "quickchat",
message: main.tfMessage.getDataValue()
});

4. To receive messages (yours and other subscribers), we need to subscribe to messages on the channel those message are being published to. Just above that click event you just added code to, there is a "start" function. Add the following code in there:

PUBNUB.subscribe({
channel: "quickchat",
callback: function(message) {
var data = main.taChat.getDataValue();
main.taChat.setDataValue(
message + (data ? "<br>" +data : ""));
}
});

Quick Test Run
Before deploying to Cloud Foundry, let's do a quick test run locally to see if all in in working order. As long as you can hit www.PubNub.com from your system, then it should work. From WaveMaker:

  1. Click the Run (or Test) button - if no errors, the app will be loaded in another browser window or tab.
  2. Once launched, enter some text in the Message text field and click the Send button - you should see the message quickly appear in the Chat Messages text area.
  3. Send a few more messages - the new messages should be inserted at the top of the Chat Messages text area.
  4. Open another browser window (preferably another brand of browser to demonstrate separate/unique client access to the app) and copy/paste the URL from your first test run window to the new browser window and launch a second instance of the app. Now send some new messages from there - you should see the messages appear in both browser windows relatively at the same time.

Note: Now remember that you are sending (publishing) messages to the PubNub server (somewhere in the cloud) using your PubNub account on the "quickchat" channel and those messages are being sent to all subscribers on that channel in your account (back to the the two browsers you have open on your system).

Deploy to Cloud Foundry
If the test run went well, then it is time to deploy the app to Cloud Foundry.

  1. Select WaveMaker menu option: File > Deploy Project > New Deployment
  2. The Deployment Type dialog is displayed: select the Cloud Foundry option and click OK
  3. The Cloud Foundry Account Info dialog is displayed: enter your CF username and password and click OK.
  4. The Settings form is displayed: change the Application Name to something that will be unique across all of the Cloud Foundry (quickchat is already taken by me). Try using your initials as a prefix to the app name: cvcquickchat, for example. Or use the Generate URL button to create a random URL that should be unique.

5. Click the Deploy Now button and wait for it to finish.
NOTE: This will take a few minutes, especially the first time you deploy because it has to generate the WAR file with all the jar files (minimal size around 25 MB) and then upload, stage and start the app in your Cloud Foundry account. Fortunately, many of the jar files in your app already exist in Cloud Foundry which maintains a repository of all these resources (from all apps in all CF accounts) so the entire app doesn't have be uploaded with every deployment.

6. When WaveMaker finishes deploying to Cloud Foundry, it will display a dialog with the URL to your app. Click it and test it as before, but this time, invite someone else from somewhere else (or a few others if you like) to join your chat room. They will probably tell you it is the biggest POS chat room they've ever seen, but just tell them it took you less than 15 minutes to create it - then send them a message with your POS chat room app telling them how you really feel about their feedback ;)

Summary
Who would have thought that creating a scalable, real time messaging Web app could be that simple.

Stay tuned to here for new installments of this series where I will provide details on how to make this chat room app more robust with a cleaner, more robust UI, using more features of the PubNub messaging service and the WaveMaker Studio as well as developing your WaveMaker apps directly in Cloud Foundry (WaveMaker Studio hosted in Cloud Foundry).

More Stories By Craig Conover

Craig Conover is a Senior Tech Labs Apps Engineer at VMware, Inc. working as a lead developer on enterprise applications integrating WaveMaker with backend systems like vCenter Orchestrator and Active Directory, deployed in a private Cloud Foundry platform.

While at WaveMaker Software, acquired by VMware in 2011, he was a sales engineer and delivered online and onsite courses. He also helped start the professional services department as lead developer and application architect on many large scale enterprise applications using WaveMaker as the key technology integrating with various backend technologies for companies such as Pioneer Natural Resources, Macy’s, ProLogic, Best Western, Nationwide and SAIC.

Craig has been in the software industry since 1992. He worked for NetDynamics, which pioneered the application server, and was acquired by Sun Microsystems. While at NetDynamics Craig produced course materials as an education consultant and instructor certifier. Craig then continue his career with Sun advancing his Java career for 10 years as a NetDynamics sustaining engineer and NetBeans tools engineer in the Web Application Framework and UML modules.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Cloud Expo Breaking News
"Since Cloud Expo is running the week of June 10, we thought it'd be a great idea to schedule our Meetup this week. That way, if you have colleagues, friends, or family in town that week for the Expo, you can invite them to join you!" With those words, the OpenStack New York Meetup Group's organizer's launched a landing page this week where anyone interested can register for the June 12 evening event.
“Cloud has everything to do with what has happened with Big Data,” explained Jason Deck, Director of Strategic Alliances at Logicworks, in this exclusive Q&A with Cloud Expo Conference Chair Jeremy Geelan. “Big Data doesn’t exist in its easily accessible way without cloud. From reduced startup costs, to cheap storage, to fast processing, to adequate security, to the easy incorporation of third-party analytics tools, cloud made Big Data accessible to customers of all sizes, with all different bud...
“Open source has always provided a number of benefits, including easing adoption costs, propagating a better understanding of the technology, and allowing for faster evolution and commercialization of products and services based on it,” noted Terry Woloszyn, Founder & CEO, Leeward Security Ltd., in this exclusive Q&A with Cloud Expo Conference Chair Jeremy Geelan. “This is clearly evident with the OpenStack and CloudStack,” Woloszyn continued, “and others that have been quickly commercialized as...
SYS-CON Events announced today that OpenStack will exhibit at SYS-CON's 12th International Cloud Expo, which will take place on June 10–13, 2013, at the Javits Center in New York City, New York. OpenStack software controls large pools of compute, storage, and networking resources throughout a datacenter, all managed by a dashboard that gives administrators control while empowering their users to provision resources through a web interface. OpenStack powers some of the most widely-used SaaS app...
SYS-CON Events announced today that BUMI (Backup My Info!), the premium provider of managed online backup and recovery solutions for small to mid-sized businesses, will exhibit at SYS-CON's 12th International Cloud Expo, which will take place on June 10–13, 2013, at the Javits Center in New York City, New York. Manhattan-based BUMI (Backup My Info!) is a premium managed service provider specializing in online data backup and recovery. Founded in 2002, the company's data backup and recovery serv...
SYS-CON Events announced today that nfina Technologies, a provider of highly reliable cloud server products, will exhibit at SYS-CON's 12th International Cloud Expo, which will take place on June 10–13, 2013, at the Javits Center in New York City, New York. nfina Technologies develops, manufactures, and markets highly reliable cloud server products, designed to solve the most demanding data center requirements in mission-critical cloud applications. Nfina’s staff has decades of experience in co...
In his session at the 12th International Cloud Expo, Dave Eichorn, Global Data Center Practice Head at Zensar, will share a case study describing how a utility services company handled the migration of its Microsoft platform to the cloud. Challenged with the time-consuming task of opening operations out of temporary offices, this company struggled with the need to simultaneously access data that was accumulated from a vast amount of data-intensive jobs. Zensar migrated the company’s application ...
“Social, mobile, analytics and cloud can’t be looked at as distinct technology trends; they are facets of the same movement and an everyday reality for consumers and businesses alike,” said Craig Sowell, IBM VP of SmartCloud Marketing, in this exclusive Q&A with Cloud Expo Conference Chair Jeremy Geelan. “This means that businesses need to start looking at trends as one: cloud is the delivery, analytics is the unique insight, social is a shareable service, and mobile is the ubiquitous access.” ...
Organizations across the world are increasingly starting to see the benefits of moving more and more services to the cloud. The focus on the cost-saving potential of cloud is rapidly shifting to completely transforming the business with cloud. As organizations are investing enormous sums on technology they are starting to realize that in order to maximize the return on investment and accelerate the business transformation process the first area of focus should be people. By ensuring the organiza...
SYS-CON Events announced today that Wowrack will exhibit at SYS-CON's 12th International Cloud Expo, which will take place on June 10–13, 2013, at the Javits Center in New York City, New York. Wowrack’s core expertise lies in high-availability Private and Public Cloud IaaS Hosting Solutions. Wowrack provides a true Hybrid service – where business release all IT management and hardware provisioning – taking the data center and server system administrative headaches off our customer’s shoulders. ...