Universal Messaging Flex - DataGroup Conflation Attributes
Enabling Conflation on DataGroups
Universal Messaging DataGroups can be configured so that conflation (merging and throttling of events) occurs when messages are published. Conflation can be carried out in several ways and these are specified using an nConflationAttributes object. The ConflationAttributes object is passed in to the DataGroup when it is created initially.
The nConflationAttributes object has two properties: action; and interval. Both of these are passed into the constructor.
The action property specifies whether published events should replace previous events in the DataGroup or be merged with them. These properties are defined by static fields:
nConflationAttributes.sDropEvents
nConflationAttributes.sMergeEvents
The interval property specifies the interval in milliseconds between event fanout to subscribers. An interval of zero implies events will be fanned out immediately.
Creating a Conflation Attributes Object
//ConflationAttributes specifying merge events and no throttled delivery
var conflattribs : nConflationAttributes =
new nConflationAttributes(Long.ZERO, nConflationAttributes.sMergeEvent);
//ConflationAttributes specifying merge events and throttled delivery at 1 second intervals
var conflattribs : nConflationAttributes =
new nConflationAttributes(new Long(0,1000), nConflationAttributes.sMergeEvent);
//ConflationAttributes specifying drop events and throttled delivery at 1 second intervals
var conflattribs : nConflationAttributes =
new nConflationAttributes(new Long(0,1000), nConflationAttributes.sDropEvent);
Create a Single nDataGroup with Conflation Attributes
var conflattribs : nConflationAttributes =
new nConflationAttributes(Long.ZERO, nConflationAttributes.sMergeEvent);
// Create a Datagroup, passing in a Listener of type nDataGroupListener and a nConflationAttributes
mySession.createDataGroup("myGroup", dataGroupCallback, dataGroupListener, conflattribs);
Create Multiple nDataGroups with Conflation Attributes
var conflattribs : nConflationAttributes =
new nConflationAttributes(0, nConflationAttributes.sMergeEvent);
var groups : Array = {"myFirstGroup", "mySecondGroup"};
mySession.createDataGroups(groups, dataGroupCallback, conflattribs);
Now we will get a call back to dataGroupsCallback and have a reference to the Universal Messaging datagroup(s) within the realm or an error.
Publishing Events to Conflated DataGroups With A Merge Policy
At this point the server will have an nDataGroup 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 = dataGroupCallback.createRegisteredEvent();
var props : nEventProperties = audEvent.properties;
props.put("bid", 0.8999);
props.put("offer", 0.9999);
props.put("close", "0.8990");
audEvent.commitChanges();
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:
props.put("bid", 0.9999);
audEvent.commitChanges();
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.
Publishing Events to Conflated DataGroups With A Drop Policy
If you have specified a "Drop" policy in your ConflationAttributes then events are published in the normal way rather than using nRegisteredEvent.
Consuming Conflated Events from a DataGroup
The subscriber doesn't need to do anything different to receive events from a DataGroup with conflation enabled. If nRegisteredEvents are being delivered then the events will contain only the fields that have changed will be delivered. In all other circumstances an entire event is delivered to all consumers.