Progress
External Program
Interfaces
Pub/Sub Messaging Examples
The Pub/Sub examples consist of sets of subscribers and publishers. You should run each messaging example interactively from its own window. Launch the subscriber first, because the message is discarded if the publisher publishes the message before there are any subscribers to the topic (or any durable subscriptions).
The path for the messaging examples depends on your operating system. The paths are:
Publishing and Subscribing With a TextMessage
Examples 1 and 2 demonstrate basic Pub/Sub messaging. Example 1 publishes a TextMessage to a topic and Example 2 subscribes to a topic and receives a TextMessage.
Follow these steps to run Examples 1 and 2:
- Run example2.p (1 of 2)
so the subscriber is running before you publish.
- Run example1.p to publish the TextMessage to a topic.
Publishing With Message Properties and Subscribing Selectively
Example 3 publishes a TextMessage from Super Golf Center to Sub Par Golf using setStringProperty. Example 4 subscribes to a topic and only receives messages addressed to “Sub Par Golf” (by passing a selector to the Subscribe call).
Follow these steps to run Examples 3 and 4:
- Run example4.p (1 of 2) first so the subscriber is running before you publish.
- Run example3.p.
Publishing With a Reply Handle, Subscribing, and Receiving an Automatic Reply
Examples 5, 6, and 7 illustrate publishing with a reply handle and receiving an automatic reply. Example 5 subscribes with an automatic reply mechanism. It can only reply to messages that have the JMSReplyTo header field. Example 6 subscribes with explicit reply by calling publish directly. It can only reply to messages that have the JMSReplyTo header field. Example 7 publishes using requestReply for receiving reply messages from subscribers. It populates the JMSReplyTo header field automatically.
Follow these steps to run Examples 5, 6, and 7:
- Run example5.p (1 of 2) so the subscriber is running before you publish.
- Run example6.p (1 of 2) to subscribe with explicit reply by calling publish directly.
- Run example7.p (1 of 2) to publish using requestReply for receiving reply messages from subscribers. It populates the JMSReplyTo header field automatically.
Publishing, Receiving, and Processing a StreamMessage
Examples 8 and 9 publish, receive, and process a StreamMessage.
Follow these steps to run Examples 8 and 9:
- Connect to the Sports database.
- Run example9.p (1 of 2) to receive the StreamMessage containing the customer names and numbers.
- Run example8.p to publish a StreamMessage containing customer names and numbers.
Publishing, Receiving, and Parsing an XMLMessage
Examples 10 and 11 create, publish, receive, and parse an XMLMessage.
Follow these steps to run Examples 10 and 11:
- Run example11.p (1 of 3) so the subscriber is running before you publish.This example subscribes, receives, and parses an XML message.
- Run example10.p to create and publish an XML message with the data of 100 people.
Publishing, Subscribing, and Receiving an XML Document In a BytesMessage
Examples 12 and 13 use a MEMPTR variable to publish and receive an XML document in a BytesMessage to prevent code-page conversions. The code pages of the document and the 4GL client do not have to match.
Follow these steps to run Examples 12 and 13:
- Run example13.p (1 of 2)
to
subscribe and receive a BytesMessage containing an XML document.
- Run example12.p
to publish the BytesMessage containing an XML document.
Publishing, Subscribing, and Receiving the Customer Table In a StreamMessage
Examples 14 and 15 use RAW transfer to publish, subscribe, and receive the customer table in a StreamMessage. Example 14 publishes the customer table in a StreamMessage; each customer record is a bytes item. Example 15 subscribes and receives the customer table in a StreamMessage; each customer record is a bytes item.
Follow these steps to run Examples 14 and 15:
- Start a server for the Sports database. Each client must connect to the database in multi-user mode.
- Run example15.p (1 of 2) so the subscriber is running before you publish.
- Run example14.p.
Publishing and Receiving a Group Of Messages In a Transaction
Examples 22 and 23 publish and receive a group of messages in a single transaction. Example 22 creates a session that is transacted for sending and Example 23 creates a session that is transacted for receiving.
Follow these steps to publish and receive a group of messages in a transaction:
- Run example23.p (1 of 2)
so the subscriber is running before you publish.
- Run example22.p to subscribe and receive messages from
example22.p
in a single transaction.
Installing an Error Handler To Handle an Asynchronous Error
Example 16 installs an error handler to detect a JMS server communication loss.
Follow these steps to install an error handler to handle an asynchronous error:
- Run example16.p.
- Shut down the SonicMQ broker to simulate the communication loss.
Installing an Error Handler For Synchronous Errors
The procedure in example17.p publishes a TextMessage to a nonexistent topic and handles the error conditions.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |