By default all messages published by a producer are delivered to all subscribers for the same destination (subject to the selector-based message filtering). Alternatively, a producer can send a message to a subtopic which is a category of messages within a destination. In that case the message is then delivered by WebORB only to the subscribers using the same subtopic (again subject to the applied selectors).
Subtopic support can be enabled at the destination level in the WEB-INF/flex/messaging-config.xml file. To enable subtopics for a destination use the <allow-subtopics> element as shown below:
<destination id="SamplePollingDestination">
<properties>
<server>
<allow-subtopics>true</allow-subtopics>
<durable>false</durable>
</server>
<message-storage-policy>weborb.messaging.v3.MemoryStoragePolicy</message-storage-policy>
<message-service-handler>weborb.messaging.v3.MessagingServiceHandler</message-service-handler>
</properties>
<channels>
<channel ref="my-polling-amf"/>
</channels>
</destination>
Both publisher and subscriber specify the name of a subtopic. If the name matches between producer and consumer, WebORB delivers published messages to the consumer. The match between the subtopic names does not have to be literal, since WebORB supports tokenized structure of the subtopic names:
maintoken[.secondaryToken][.additionalToken]
To receive message from more than one subtopic, subscribers can use the wildcard character (*) in place of any tokens in the subtopic name. For instance, a subscriber could subscribe to the following subtopic: "com.foo.*", and the publisher sends messages to "com.foo.bar" and "com.foo.baz". In this case the messages published to either subtopic will be delivered to the consumer.
The wildcard character in the last position will match any token in that position as well as tokens after it. For instance, subtopic com.foo.* will match all of the following: com.foo.bar, com.foo.abc.def, etc. However, the wildcard character in any position other than the last will match only one token. For example, subtopic com.*.foo will match com.abc.foo and com.123.foo, but will not match com.foo.
The following examples demonstrate publishing and subscribing to a subtopic:
Creating a Flex consumer with a selector: var consumer:Consumer = new Consumer(); Publishing a message with a header: var producer:Producer = new Producer(); |
Importing WebORB.js and setting up the URLs <script language="javascript" src="WebORB.js"></script> Creating a JavaScript consumer with a selector: var myConsumer = new Consumer("SamplePollingDestination", new Async(messageReceived, handleFault)); Publishing a message with headers: var myProducer = new Producer("SamplePollingDestination"); |
Applications using the WeborbClient API must make sure to reference weborbclient.jar. Creating a consumer with a selector: WeborbClient consumer = new WeborbClient("http://localhost/weborb/weborb.aspx", "SamplePollingDestination"); Publishing a message with headers: WeborbClient producer = new WeborbClient("http://localhost/weborb5/weborb.aspx", "SamplePollingDestination"); |
Creating a .NET consumer: public static string WeborbUrl = "http://localhost/weborb5/weborb.aspx"; // Can also change to "rtmpt://localhost:port/root"; Creating a .NET publisher: public static string WeborbUrl = "http://localhost/weborb5/weborb.wo"; // Can also change to "rtmpt://localhost:port/root"; |