5

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>

1 Answer 1

7

The event queue table has two columns related to the matter.

They are RaiseGlobally (true by default) and RaiseLocally (false by default).

These flags control the event execution appropriately (i.e. if RaiseGlobally is false, the event will not be processed by remote servers)

In order to control those flags, you can use the second overload of the QueueEvent<T> method: EventManager.QueueEvent<EventRemote>(new EventRemote {ItemId = "bas"}, true, true)

The first flag is for RaiseGlobally, the second is for RaiseLocally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.