Universal Messaging 9.9 | Universal Messaging Developer Guide | Web Client APIs | Web Developer's Guide for Adobe Flex | Publish / Subscribe using Channels / Topics | Durable channel consumers and named objects
 
Durable channel consumers and named objects
Universal Messaging provides the ability for asynchronous consumers to be durable. Durable consumers allow state to be kept at the server with regard to what events have been consumed by a specific consumer of data.
Universal Messaging supports durable consumers through use of Universal Messaging named objects (see Named Objects) as shown by the following example code.
Names objects can also be managed via the enterprise manager.
Durable Consumer
An example of how to create a named object that begins from event id 0, persistent and is used in conjunction with an asynchronous event consumer:

public class mySubscriber implements nEventListener {

// construct your session
// and channel objects here

private var nobj:nNamedObject;

public function mySubscriber(channelIn:*):void {
if(channelIn is nChannel){
myChannel.createNamedObject(namedObjectCreatedCB, "unique1",
Long.ZERO, true);
}
}

public function namedObjectCreatedCB(named:*):void {
if(named is nNamedObject){
nobj= nNamedObject(named)
myChannel.addSubscriber(this , subscribedCB, nobj,true);
}
}

public function go(event:*):void {
if(event is nConsumeEvent){
//process event
}
}
}
Channel consumers allow message selectors to be used in conjunction with named objects. Please see the API documentation for more information.
There are also different ways in which events consumed by named consumers can be acknowledged. By specifying that 'auto acknowledge' is true when constructing consumers, then each event is acknowledged as consumed automatically. If 'auto acknowledge' is set to false, then each event consumed has to be acknowledged by calling the ack() method:

public function go(event:*):void {
if(event is nConsumeEvent){
//process event
nConsumeEvent(event).ack();
}
}
Priority
Two subscribers can hold a subscription to the same named object. One is given priority and will process events during normal operation. If, however, the subscriber with priority is disconnected for whatever reason, and is unable to process events, the second subscriber to that named object will take over and continue to process events as they come in. This allows failover, with backup subscribers handling events if the subscriber with priority goes down.
To do this, we simply create the subscriber with a boolean specifying if this subscriber priority. Only one subscriber is allowed priority at any given time. An example of a named object specifying priority is shown below:

myChannel.createNamedObject(namedObjectCreatedCB, subname, startEid, persistent,
cluster, priority);

Copyright © 2013-2015 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release