Navigation:  Messaging and Streaming > Publish-Subscribe > Message Filtering >

Subtopics

Previous pageReturn to chapter overviewNext page
Show/Hide Hidden Text

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:

 

hmtoggle_plus1Flex/AIR Publisher an Consumer

Creating a Flex consumer with a selector:

var consumer:Consumer = new Consumer();
consumer.destination = "SamplePollingDestination";
consumer.addEventListener( MessageEvent.MESSAGE, gotMessage );
consumer.subtopic = "my.cool.subtopic";
consumer.subscribe();

Publishing a message with a header:

var producer:Producer = new Producer();
producer.destination = "SamplePollingDestination";
var message:AsyncMessage = new AsyncMessage();
message.body = "Hey Consumer!";
producer.subtopic = "my.cool.subtopic";
producer.send( message );

 

hmtoggle_plus1JavaScript Publisher/Consumer

Importing WebORB.js and setting up the URLs

<script language="javascript" src="WebORB.js"></script>
// defaultMessagingURL is used if the Web Sockets support is available in the browser
webORB.defaultMessagingURL = "ws://localhost:2037";
// defaultRemotingURL is used for polling in case if Web Sockets are not available
webORB.defaultRemotingURL = "http://localhost/weborb5/weborb.aspx ";

Creating a JavaScript consumer with a selector:

var myConsumer = new Consumer("SamplePollingDestination", new Async(messageReceived, handleFault));
// the selector property is set to a query.
// WebORB will check if a published message contains the
// "CITYNAME" header with the value "Dallas". If it does,
// the message will be delivered to this consumer
var subtopic = "my.cool.subtopic";
myConsumer.subscribe( subtopic );

Publishing a message with headers:

var myProducer = new Producer("SamplePollingDestination");
var headers = new Object();
var subtopic = "my.cool.subtopic";
myProducer.send( "Hey Consumer!", undefined, subtopic );

 

hmtoggle_plus1Java and Android Publisher/Consumer

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");
IResponder responder = new MyResponder();
String subtopic = "my.cool.subtopic";
consumer.subscribe( responder, subtopic );

Publishing a message with headers:

WeborbClient producer = new WeborbClient("http://localhost/weborb5/weborb.aspx", "SamplePollingDestination");
String subtopic = "my.cool.subtopic";
producer.publish( "Hey Consumer!", subtopic );

 

hmtoggle_plus1.NET Publisher and Consumer

Creating a .NET consumer:

public static string WeborbUrl = "http://localhost/weborb5/weborb.aspx"; // Can also change to "rtmpt://localhost:port/root";
WeborbClient consumer = new WeborbClient( WeborbUrl, "SamplePollingDestination" );
SubscribeResponder responder = new SubscribeResponder(
         message => Dispatcher.BeginInvoke(() =>
         {
           IAdaptingType[] body = message.GetBody();
           object message = body[0].defaultAdapt();
           System.Console.WriteLine( message + "\n" );
        }),
        fault => Dispatcher.BeginInvoke(() => System.Console.WriteLine( fault.Message + "\n" )));
String subtopic = "my.cool.subtopic";
consumer.Subscribe( responder, subtopic );

Creating a .NET publisher:

public static string WeborbUrl = "http://localhost/weborb5/weborb.wo"; // Can also change to "rtmpt://localhost:port/root";
private WeborbClient publisher = new WeborbClient( MainPage.WeborbUrl, "SamplePollingDestination" );
AsyncMessage asyncMessage = new AsyncMessage();
asyncMessage.body = "Hey Consumer!";
String subtopic = "my.cool.subtopic";
publisher.Publish( asyncMessage, null, subtopic );