0

Cross Server Events

Posted on 15 November 2009 and tagged with ,

The Events Management System is a powerful new feature introduced in EPiServer CMS and is part of the public EPiServer API. It's based on WCF and broadcast messages between servers in the same network using UDP (or TCP). These events is mainly used to send cache update events between the servers. The Events Management System is however not limited to only this usage. Here is a quick how-to on using remote events in your own code.

1. Configure your site to use remote events.

2. Create two new unique guids. The first guid is used to get a handle of the new custom remote event type. The other guid is sent along with the remote event to identify the sender.

private static Guid _eventID = new Guid("{CF3321B9-D616-4a35-AA25-A2B7D881D61C}");
private static Guid _raiserID = new Guid("{CF3321B9-D616-4a35-AA25-A2B7D881D61D}");


3. Create a new instance of the remote event client.

private static EPiServer.Events.Clients.Event _remoteEvent;


_remoteEvent = Events.Clients.Event.Get(_eventID);


4. Subscribing to the remote events.

_remoteEvent.Raised += new EPiServer.Events.EventNotificationHandler(RemoteEvent_Received);


///<summary>
/// Receives remote events
///</summary>
///<param name="sender"></param>
/// <param name="e"></param>
static void RemoteEvent_Received(object sender, EPiServer.Events.EventNotificationEventArgs e)
{
   //Remote event received -> do some work  
   System.Diagnostics.Debug.WriteLine("Remote event received: " + e.Param);
 }


5. Raising remote events.

/// <summary>
/// Raises a remote event
/// </summary>
/// <param name="param">Information to broadcast to all servers</param>
public static void Raise(string param)
{
   if (_remoteEvent != null)
   {
        _remoteEvent.Raise(_raiserID, param);
    }
}


<asp:TextBox ID="txtParam" runat="server" />
<asp:Button ID="btnRaiseRemoteEvent" runat="server" OnClick="btnRaiseRemoteEvent_Click" Text="Raise remote event" />

<script runat="server">
    protected void btnRaiseRemoteEvent_Click(object sender, EventArgs e)
    {
         EPiServer.MyRemoteEventExample.Raise(txtParam.Text);
    }
</script>

ClientGUI

Thats it. You can download and run the remote event listener to verify that the events are sent correctly across the servers.

RemoteEventListener

Click here to download the complete sample code.

Add comment





Loading


Disclaimer

© Copyright 2009, Jarle Friestad. The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Widget Twitter not found.

Root element is missing.X

Month List