Multitopic producers and consumers

The MultiTopicProducer component sends messages to a destination with zero or more subtopics. It is like the standard Producer component but can direct the message to any consumer that is subscribing to any one of a number of subtopics. If the consumer is a MultiTopicConsumer component and that consumer has subscribed to more than on subtopic in the list of subtopics used by the MultiTopicProducer, the consumer only receives the message once.

The following code creates a MultiTopicProducer component that sends messages to two subtopics:

... 
<mx:Script       >  
... 
    function sendMessage():void { 
        var producer:MultiTopicProducer = new MultiTopicProducer(); 
        producer.destination = "NASDAQ"; 
        var msg:AsyncMessage = new AsyncMessage(); 
        msg.headers.operation = "UPDATE"; 
        msg.body = {"SYMBOL":50.00}; 
        // only send to subscribers to subtopic "myStock1" and "myStock2" 
        msg.addSubtopic("myStock1"); 
        msg.addSubtopic("myStock2"); 
        producer.send(msg);     
    } 
... 
</mx:Script> 
...

Unlike the standard Consumer component, the MultiTopicConsumer component lets you register subscriptions for a list of subtopics and selector expressions at the same time from a single message handler. Where the Consumer component has subtopic and selector properties, this component has an addSubscription(subtopic, selector) method you use to add a new subscription to the existing set of subscriptions. Alternatively, you can populate the subscriptions property with a list of SubscriptionInfo instances that define the subscriptions for the destination.

The following ActionScript code creates a MultiTopicConsumer component that subscribes to two subtopics:

... 
<mx:Script> 
... 
    private functio n initConsumer():void{ 
        consumer.destination = "NASDAQ"; 
        consumer.addEventListener(MessageEvent.MESSAGE, messageHandle     r) ; 
        consumer.addEventListener(MessageFaultE  v e n t.FAULT, faultHandler); 
        consumer.addSubscription("myStock1", "operation IN ('BID', 'Ask')"); 
        consumer.addSubscription("myStock2", "operation IN ('BID', 'Ask')"); 
        consumer.subscribe(); 
... 
</mx:Script> 
...