Publish and Subscribe Module
The Publish and Subscribe module demonstrates the Progress named-event functionality. The module uses two event publishers, publisher1.w
and publisher2.w
, and two event subscribers, subscriber1.w
and subscriber2.w
. A driver procedure, subpub.p
, starts the publisher procedures as persistent procedures. The driver then starts the subscriber procedures, passing to them the handles for the persistent publisher procedures.
Choose the Publish and Subscribe button on the SportsPro main window to launch this module:
The publish and subscribe functionality works like an e-mail alias. When users subscribe to an e-mail alias, they receive messages whenever messages are published to that alias. Other persistent procedures running in the same session can locate a procedure that generates an event of interest. The persistent procedures subscribe to that event by mapping the event to an internal procedure that is executed when the event occurs.
Table 2–9 describes the major objects used in the Publish and Subscribe module.
Table 2–9: Components Of the Publish and Subscribe Module
Object Or File Name
|
Object Type
|
Function
|
suppub.p
|
Procedure file
|
Runs the four windows as persistent procedures and passes the handles for the publishers to the subscribers.
|
publisher1.w
|
SmartWindow
|
Serves as a container for the objects in it.
|
BUTTON–1
|
Button
|
Publishes a named event, “EventOne,” which causes the EventOne internal procedure to run in any subscriber for which it currently has a handle. It reports the number of subscribers to the event from the replies it receives.
|
BUTTON–2
|
Button
|
Publishes a named event, “EventTwo,” which causes the EventTwo internal procedure to run in any subscriber for which it currently has a handle.
|
publisher2.w
|
SmartWindow
|
Serves as a container for the objects in it.
|
BUTTON–1
|
Button
|
Publishes a named event, “EventOne,” which causes the EventOne internal procedure to run in any subscriber for which it currently has a handle. It reports the number of subscribers to the event from the replies it receives.
|
BUTTON–2
|
Button
|
Publishes a named event, “EventTwo,” which causes the EventTwo internal procedure to run in any subscriber for which it currently has a handle.
|
subscriber1.w
|
SmartWindow
|
Serves as a container for the objects in it.
|
BUTTON–3
|
Button
|
Subscribes to both named events in publisher1.w and to “EventOne” in publisher2.w .
|
BUTTON–4
|
Button
|
Unsubscribes from “EventOne” in publisher1.w.
|
BUTTON–5
|
Button
|
Unsubscribes from “EventOne” in both publishers.
|
subscriber2.w
|
SmartWindow
|
Serves as a container for the objects in it.
|
BUTTON–6
|
Button
|
Subscribes to “EventTwo” in both publishers and to “EventOne” in publisher1.w .
|
For more information on publishing and subscribing to named events, see the chapter on named events in the Progress Programming Handbook
.