Notification Service Example: News

Description

This example uses the OpenFusion Notification Service publish/subscribe model and includes a persistent consumer (the Subscriber) to illustrate guaranteed event delivery. The design of this example is relatively sophisticated; for a more simple example, please refer to the Mail example.

Synopsis

The News example includes a Subscriber that provides the opportunity to subscribe to news broadcasts reporting weather and stock-exchange news bulletins. A Publisher is also included that broadcasts news for weather and stocks, and publishes its intention to do so. Subscription to news broadcasts is based on an index indicating the importance of the news item. For example, a stock-broker presumably would be interested in news on stocks and shares, but might also want to keep an eye on weather bulletins. Alternatively, the weather-man would be interested in weather forecasts, but maybe to a lesser degree also interested in news from the financial markets.

Design

The example uses a single event channel and the following classes:

The following commands control the Subscriber:

The following commands control the Publisher:

How to Build This Example

UNIX

These instructions are based on the Solaris gcc3.2 compiler makefiles.

  1. Ensure that the following environment variables are set:
  2. Ensure that your environment is set up for your compiler and linker. For example, for gcc3.2:

    PATH=/usr/local/gcc-3.2/bin:/usr/ccs/bin:$PATH; export PATH

    LD_LIBRARY_PATH=/usr/local/gcc-3.2/lib:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH

  3. Change to the <TAO install dir>/examples/cc directory.
  4. If you have not done so already, enter the make command to run the makefile. This will compile all of the OpenFusion examples.

Windows NT

  1. Set the environmental property TAO_ROOT=<TAO install dir> where <TAO install dir> is the location into which you have installed TAO.
  2. A global example Microsoft Visual C++ project has been provided. This is called <TAO install dir>\examples\cc\cc.dsw. Double-click on the project file to load it into Microsoft Visual C++. When loaded, change the Common project from debug mode to release mode using the Build | Set Active Configuration menu option.
  3. Build the Common files.
  4. Build the NotificationNewsExample files.
  5. Build the Publisher files.
  6. Build the Subscriber files.

How to Run This Example

To run the example, ensure that the Notification Service is running with no event channels created. If event channels are already created (for example, if you have already run the mail example) then use the Restore command in the OpenFusion Administration Manager.

In order to run the OpenFusion Notification Service you must first install the OpenFusion TCS - JacORB with OpenFusion CORBA Services distribution. This can be obtained from the downloads page by following the OpenFusion CORBA Products software link.

  1. Windows NT: Start a DOS window. Ensure that your path contains:

    <TAO install dir>\bin;<TAO install dir>\examples\cc\bin

    UNIX: Ensure that the environment variable LD_LIBRARY_PATH includes the path to where the common files and the News files were compiled:

    LD_LIBRARY_PATH=<TAO install dir>/examples/cc/Common:<TAO install dir>/examples/cc/Notification/news:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH

    Change to the <TAO install dir>/examples/cc/Notification/news/subscriber directory.

  2. Start the server by launching a Subscriber:
    newsSubscriber -ORBInitRef NotificationService=file://<OF_INSTALL_DIR>/domains/OpenFusion/localhost/NotificationService/NotificationSingleton/NotificationSingleton.ior

    This program will reply with the prompt "ADMIN>" and will then respond to commands as described above.

  3. Configure its properties by subscribing to News broadcasts with given priorities. As an example, at the ADMIN> prompt, type:
    subscribe weather 1

    followed by

    subscribe stock 5
  4. Listen for published events by typing the command:
    listen
  5. On UNIX, change to the <TAO install dir>/examples/cc/Notification/news/publisher directory.

  6. In a new window, ensure that all environment variables are set as above. Start the client by launching a Publisher:
    newsPublisher -ORBInitRef NotificationService=file://<OF_INSTALL_DIR>/domains/OpenFusion/localhost/NotificationService/NotificationSingleton/NotificationSingleton.ior

    This program will reply with the prompt "ADMIN>" and will then respond to commands as described above.

  7. Publish the fact that news events for weather and stock are available by typing the command publish weather and then publish stock. Next, broadcast some news from the Publisher by typing the commands broadcast weather and broadcast stock. The Subscriber will receive the news events provided that the priority of the randomly generated broadcast is higher than that subscribed to.

top
[top]


© PrismTech Limited 2002