The Merge Engine and Event Deltas
In order to streamline publish/subscribe applications it is possible to deliver only the portion of an event's data that has changed rather than the entire event. These event deltas minimise the amount of data sent from the publisher and ultimately delivered to the subscribers.
The publisher simply registers an event and can then publish changes to individual keys within the event. Subscribers can be configured to get callbacks which contain either the entire event or just the changed key(s). Either way, only the key(s) that have changed are delivered over the wire to the subscribing client.
Publisher - Registered Events
In order to publish event deltas the publisher uses the Registered Event facility available on a Universal Messaging Channel. Please note that the channel must have been created with the Merge Engine and it must have a single Publish Key. The publish key represents the primary key for the channel and the registered events. So for example if you are publishing currency rates you would setup a channel as such:
//Firstly, create the ChannelAttributes for a simple channel with unlimited capacity
// and no TTL.
var cattr:nChannelAttributes = new nChannelAttributes();
cattr.name = "RatesChannel";
cattr.type = nChannelAttributes.SIMPLE_TYPE;
// This next line tells the server to Merge incoming events based on the publish
// key name and the name of the registered event
cattr.useMergeEngine = true;
// Now create the Publish Key (See publish Keys for a full description
var keys:Array = new Array();
cattr.publishKeys = keys;
// Now create the channel
At this point the server will have a channel created with the ability to merge incoming events from Registered Events. The next step is to create the Registered events at the publisher.
var audEvent:nRegisteredEvent = (e as nChannel).createRegisteredEvent("AUD");
var props:nEventProperties = audEvent.properties;
You now have a nRegisteredEvent called audEvent which is bound to a ccy value of "AUD". We then set the properties relevant to the application, finally we call commitChanges(), this will send the event, as is, to the server. At this point if the bid was to change then that individual field can be published to the server as follows:
This code will send only the new "bid" change to the server. The server will modify the event internally so that any new client subscribing will receive all of the data, yet any existing subscribers will only receive the change.
Subscriber - nEventListener
The subscriber implements nEventListener in the usual way and does not need to do anything different in order to receive either event deltas or snapshots containing the result of one or more merge operations. The standard nEventListener will receive a full event when the subscriptions is initiated. Thereafter it will receive only deltas. If at any time the user is disconnected then it will receive a fresh update of the full event on reconnection - followed by a resumption of delta delivery.
If you wish to differentiate between snapshot events and delta events then the nConsumeEvent attributes can be used as follows:
For more information on Universal Messaging publish / subscribe, please see the API documentation.