Stock
Ticker - A Sample Web Application for Event Publishing
Purpose
The purpose
of the Stock Ticker web application is to demonstrate the use of event
publishing in a business scenario.
Software Prerequisite
The
following software is required for running the Stock Ticker web application:
For
installation details of all software above please refer to their corresponding
documentation.
Tips:
One-Time Setup of xmlPubTk, Tomcat, WebSphere MQ,
and Ant
The following
tasks need to be done first before running the Stock Ticker web application:
Preparing Q Capture
After Q
Capture’s installation the following tasks need to be completed. The script
files used below are located under Stock Ticker’s script/ directory.
Preparing WebSphere
MQ
The step
below need to be done:
Content of asnqwxml.zip
The Stock
Ticker’s script files, source and binary code, as well as the XML Publication
Toolkit are compressed in asnqwxml.zip. You need to uncompress it using
compression software such as WinZip or PkZip. The content
of asnqwxml.zip is organized as follows:
stockticker/
dist/
stockticker.war
scripts/
capparms.sql
createdb.sql
stockdata_dlt.sql
stockdata_init.sql
stockdata_ins.sql
stockdata_upd.sql
stocks.mq
stocks.sql
stockxpub.sql
src/
com/
ibm/
db2/
samples/
repl/
publication/
StockPrice.java
StockPriceListener.java
web/
WEB-INF/
web.xml
stockticker.jsp
build.xml
README.htm
Deploying Stock Ticker to Tomcat
You need to
install the Stock Ticker’s binary files to Tomcat before running it. Its binary
files are archived in the WAR (Web Archive) file stockticker.war under Stock Ticker’s dist/ directory.
The installation
steps are:
Initializing Stock Price
Before you
run Stock Ticker web application you need to initialize the Stock Ticker’s
application tables with:
db2 –tvf stockdata_init.sql
The script
file is located under Stock Ticker’s scripts/ directory and contains database transactions that populate
the CURRENCIES and STOCKS table with initial data and clean the STOCK_PRICES
table content.
Running Stock Ticker
Follow the
steps below to run the Stock Ticker web application:
The Stock Ticker’s web page will be displayed. No stock price information will
be shown because no stock price data has been entered yet.
Activating and Deactivating the
Stock Price XML Publication
On the
bottom part of the Stock Ticker’s web page there are two buttons labeled with
“Activating XML Publication” and “Deactivating XML Publication”
The
activation or deactivation of the stock price XML publication will be carried
out by selecting the corresponding button.
Below the
two buttons there is a message that tells the status of the stock price XML
publication. The status can be either ‘Active’ or ‘Inactive’.
The
activation/deactivation of the stock price XML publication work as follows:
Publishing Stock Price Data
In order to
publish stock price data we need to do the following:
1. Activate the stock price XML
publication if it is not active and make sure that the XML publication is in
active state.
2. Execute database transactions
against the STOCK_PRICES table. There are sample script files stockdata_ins.sql, stockdata_ins.sql, and stockdata_ins.sql that contains such database transactions.
Insert first some stock price data with
db2 –tvf stockdata_ins.sql
3. The Stock Ticker’s web page will
automatically be refreshed every 5 seconds. You will see then the stock price
information displayed on the web page. Please note that only stocks that have
price change greater than 1 unit of currency will be displayed.
4. Make some updates on the stock price
data inserted previously with:
db2 –tvf stockdata_upd.sql
The displayed stock price information will be updated
automatically.
5. Delete stock price data with:
db2 –tvf stockdata_dlt.sql
The displayed stock price information will be updated automatically.
You also
can try to deactivate the XML publication and make sure that the XML
publication’s state becomes inactive. Then execute some database transactions
that update the stock price data. The stock price data should remain unchanged.
This is because no Transaction messages were published by Q Capture since the
XML publication had been deactivated.
Other Tasks
Working with Ant
With Ant
and the delivered sample build file build.xml located under Stock Ticker home
directory you can accomplish other tasks such as:
1. Building Stock Ticker web
application. Let suppose you want to modify the Stock Ticker web application by
updating the Java source files. After you made your changes you can re-compile
them Stock Ticker by simply running:
ant compile
The binary files will be then put under
Stock Ticker’s build/ directory.
2. Once you are ready to distribute the
updated Stock Ticker web application you can create its binary distribution
with:
ant dist
Ant will create the WAR
file stockticker.war that will be put under dist/ directory.
3. If a clean build is desired then run:
ant cbuild
Ant will remove old build/ and dist/ directory, compile the source codes, put the newly
generated object files into the build/ directory, re-create the binary distribution and put it to
the dist/ directory.
4. If you want to install/remove the
Stock Ticker web application to/from Tomcat then run:
ant [deploy | undeploy]
5. If you want to have a clean
installation of the Stock Ticker web application to then run:
ant cdeploy
Ant will make a clean build, a new distribution file, and finally install the
distribution file on Tomcat.
6. If you have installed Stock Ticker
and simply want Tomcat to recognize that you have updated Java classes then
run:
ant reload
7. If you want Tomcat to list all
installed web applications then run:
ant reload
This use useful to determine whether the Stock Ticker
has been installed on Tomcat or not.