Back to Notification Service Examples Page
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.
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.
The example uses a single event channel and the following classes:
Other files used by this example include: NewsSubscriber.hh, NewsSubscriber.cpp, NewsPublisher.hh, NewsPublisher.cpp, NewsInputManager.hh, NewsInputManager.cpp, PushConsumer.hh, PushConsumer.cpp, and PushSupplier.cpp.
The following commands control the Subscriber:
subscribe <domain> <priority>
makes ready the Subscriber with event filters describing
the event type and the priority of the subscribed news broadcast.
The applied filters are configured with an event-type domain name
(either "weather" or "stock"), and a constraint to filter out unwanted
news events based on the given priority. Only news events carrying
a priority greater than that specified will be received by the Subscriber.
The given priority is expected as an Integer in the range 1 to 10;
the higher the number, the more significant the news.
listen
activates
the Subscriber servant instance on the Object Adapter and makes the ORB ready
to receive remote function invocations. The Subscriber (consumer) is
initialised with a suspended connection to the event-channel proxy.
The following commands control the Publisher:
publish <domain>
publishes an offer of news event types to the connected event channel
according to the given domain. Any connected Subscriber will be informed
if this results in a change to the channel event-type aggregate. In the
case where a suspended Subscriber has an interest in the offered news event
types, the Subscriber will resume its connection to the channel.
withdraw <domain>
removes an offer of news event types from the connected event-channel
according to the given domain. Any connected Subscriber will be informed
if this results in a change to the channel event-type aggregate. In the
case where a connected Subscriber has no interest in the remaining offered
news event types, the Subscriber will suspend its connection to the channel.
broadcast <domain>
pushes an event.
The event type is denoted by the given domain. The actual news item is selected
at random from a pre-defined list, and is sent together with the randomised
priority associated with the news broadcast. Any connected Subscribers will
receive the news broadcast if the filter priority is less than that broadcast
in the event.
exit
will stop the Publisher.
These instructions are based on the Solaris gcc3.2 compiler makefiles.
ACE_ROOT=<TAO install dir>; export ACE_ROOT
TAO_ROOT=<TAO install dir>; export TAO_ROOT
SHLIB_PATH=$TAO_ROOT/lib; export SHLIB_PATH
LD_LIBRARY_PATH=$TAO_ROOT/lib:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH
PATH=$PATH:$TAO_ROOT/bin; export PATH
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
<TAO install dir>/examples
directory.
<Local Copy>/cc
directory.
make
command to run the makefile. This will compile all of the OpenFusion examples.
TAO_ROOT=<TAO install dir>
where
<TAO install dir>
is the location into which you have installed
TAO.
<TAO install dir>\examples
directory.
<Local Copy>\cc\Common
directory.
<Local Copy>\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 Build | SetActive Configuration.
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.
<TAO
install dir>\lib;<Local
Copy>\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=<Local Copy>/cc/Common:<Local Copy>/cc/Notification/news:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH
Change to the <local copy >/cc/Notification/news/subscriber
directory.
subscriber -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.
ADMIN>
prompt,
type:
subscribe weather 1
followed by
subscribe stock 5
listen
The Subscriber will indicate that no news events of interest are available at this time and suspend its connection to the event channel.
On UNIX, change to the <local copy>/cc/Notification/news/publisher
directory.
publisher -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.
publish weather
. The connected Subscriber
will indicate that events of interest are available (because these
have been subscribed to), and resume its connection. 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.