I am creating a custom event to allow CD to inform CM about a specific user action in a production environment. My local development environment is a single server. Despite subscribing to the remote event, I do not see the remote event handler firing in my environment. Is this the expected behavior? Does my server not see the remote event because it is the server that raised it?
Code:
using Sitecore.Pipelines;
using System;
namespace Test.Website.Configuration.Events
{
public class EventRemote
{
public string ItemId { get; set; }
}
public class EventHandlers
{
public virtual void InitializeFromPipeline(PipelineArgs args)
{
Sitecore.Diagnostics.Log.Error("EventHandlers.InitializeFromPipeline() called", this);
var action = new Action<EventRemote>(RaiseRemoteEvent);
Sitecore.Eventing.EventManager.Subscribe<EventRemote>(action);
}
private void RaiseRemoteEvent(EventRemote myEvent)
{
Sitecore.Diagnostics.Log.Error("EventHandlers.RaiseRemoteEvent() called", this);
Sitecore.Events.Event.RaiseEvent("event:happened:remote", new object[] { myEvent.ItemId });
}
}
public class EventManager
{
public static void RaiseEventRemote()
{
Sitecore.Diagnostics.Log.Error("EventManager.RaiseEventRemote() called", typeof(EventManager));
var parameters = new object[] { new Guid().ToString() };
Sitecore.Events.Event.RaiseEvent("event:happened", parameters);
Sitecore.Eventing.EventManager.QueueEvent<EventRemote>(new EventRemote {ItemId = "bas"});
}
public void OnEvent(object sender, EventArgs args)
{
Sitecore.Diagnostics.Log.Error("EventManager.OnEvent() called", this);
}
public void OnEventRemote(object sender, EventArgs args)
{
Sitecore.Diagnostics.Log.Error("EventManager.OnEventRemote() called", this);
}
}
}
Config patch:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<initialize>
<processor type="Test.Website.Configuration.Events.EventHandlers, Test.Website" method="InitializeFromPipeline" />
</initialize>
</pipelines>
<events>
<event name="event:happened">
<handler type="Test.Website.Configuration.Events.EventManager, Test.Website" method="OnEvent" />
</event>
<event name="event:happened:remote">
<handler type="Test.Website.Configuration.Events.EventManager, Test.Website" method="OnEventRemote" />
</event>
</events>
</sitecore>
</configuration>