1

I am trying to get a remote event fired from CD server to CM server and then CM server to create the item required in Sitecore 9.1.1. I can see the event gets added to the database but it never gets executed. Below are my configuration and code

Config:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
  <sitecore>
    <hooks role:require="Standalone or ContentManagement">
      <hook type="Sitecore.Feature.PageFeedback.Events.UpdatePageRatingHook, Sitecore.Feature.PageFeedback"></hook>
    </hooks>
    <event name="updatepagerating:remote">
      <handler type="Sitecore.Feature.PageFeedback.Events.UpdatePageRatingEventHandler, Sitecore.Feature.PageFeedback" method="OnUpdatePageRatingRemote"></handler>
    </event>
  </sitecore>
</configuration>

Hook:

namespace Sitecore.Feature.PageFeedback.Events
{
  public class UpdatePageRatingHook : IHook
  {
    public void Initialize()
    {
      Log.Info("Subscribing to updatePage rating event", this);
      EventManager.Subscribe(new Action<UpdatePageRatingModel>(UpdatePageRatingEventHandler.Run));
    }
  }
}

Event args:

namespace Sitecore.Feature.PageFeedback.Events
{
  public class UpdatePageRatingEventArgs : EventArgs, IPassNativeEventArgs
  {
    private UpdatePageRatingModel _evt;

    public UpdatePageRatingEventArgs(UpdatePageRatingModel evt)
    {
      _evt = evt;
    }

    public Guid pageId
    {
      get { return _evt.pageId; }
    }

    public int Score
    {
      get { return _evt.Score; }
    }

    public Guid? FeedbackReference
    {
      get { return _evt.FeedbackReference; }
    }
  }
}

EventHandler:

namespace Sitecore.Feature.PageFeedback.Events
{
  public class UpdatePageRatingEventHandler
  {
    private readonly IPageFeedbackService _feedbackService = DependencyResolver.Current.GetService<IPageFeedbackService>();
    /// <summary>
    /// The method is the method that you need to implement as you do normally
    /// </summary>
    public virtual void OnUpdatePageRatingRemote(object sender, EventArgs e)
    {
      Log.Info("Executing page rating event",this);
      if (e is UpdatePageRatingEventArgs)
      {
        var args = e as UpdatePageRatingEventArgs;
        Log.Info("submitting stars feedback", this);
        _feedbackService.SubmitStarsFeedback(new StarsFeedbackModel()
        {
          PageId = args.pageId,
          FeedbackReference = args.FeedbackReference,
          Score = args.Score
        });
      }
    }

    // This methos is used to raise the local event
      public static void Run(UpdatePageRatingModel evt)
      {
        Log.Info("Raising event locally for pagefeedback", typeof(UpdatePageRatingEventHandler));
        UpdatePageRatingEventArgs args = new UpdatePageRatingEventArgs(evt);
        Event.RaiseEvent("updatepagerating:remote", new object[] {args});
      }
    }
  }

Creating an event:

public ID StartsFeedBackEvent(StarsFeedbackModel model)
    {
      var database = Sitecore.Configuration.Factory.GetDatabase("web");
      var eventQueue = database.RemoteEvents.EventQueue;
      eventQueue.QueueEvent(new UpdatePageRatingModel()
      {
        pageId = model.PageId,
        FeedbackReference = model.FeedbackReference,
        Score = model.Score
      });
      return new ID(model.FeedbackReference.Value);
    }

Event entry in Database:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.