Alachisoft NCache 4.1 - Online Documentation

Custom Notifications

 
NOTE: This feature is not available in NCache Express and Professional edition.
 
NCache now provides the ability to generate custom notifications. A producer application can call a single method that invokes handlers on all the subscribers of the custom notification event. In a clustered environment, custom notifications are quite convenient mean of communication among the participants of the cluster. Even in local environment, a producer consumer style communication between applications is easily achieved using this facility.
Using custom notifications is a two step process. One is a producer end of notification and other is a consumer end.
Add the following namespaces in your application for using events:
 
using Alachisoft.NCache.Web.Caching;
using Alachisoft.NCache.Runtime;
 
Send Custom Notifications
 
Producers will raise notifications by simply calling.
 
_cache.RaiseCustomEvent("NotificationID", DateTime.Now);
 
The first parameter of the method is application defined notification code/id. This parameter can be used to logically distinguish between notification types on the consumer end, it can be thought of an opcode. The second parameter is the operand of the opcode, which again is application defined.
 
Register to receive Custom Notifications
 
On the consumer end there is a little more work to be done then just a method call. Cache provides a CustomEvent of type CustomEventCallback, which can be subscribed by the consumer end of the notifications. Here is an example on how to do that
 
_cache.CustomEvent += new CustomEventCallback(this.OnApplicationEvent);
_cache.RaiseCustomEvent("NotificationID", DateTime.Now);
public void OnApplicationEvent(object notifId, object data)
{
switch((string)notifId)
{
case "NotificationID":
HandleItem((ItemData)data);
break;
}
}
 
The last line subscribes to the Custom Notification event of the Cache. Note that, if the consumer handler for a synchronous notification raises a notification that in turn causes the producer to raise the same event synchronously, a deadlock due to infinite recursion may be imminent. It is, therefore, recommended that you carefully plan the flow of notifications while using synchronous notifications.
 
 
See Also
 
Copyright © 2005-2012 Alachisoft. All rights reserved.