1

I am trying to raise remote events from CD. So that CM can read EventQueue and perform CRUD operation and publish.

I wanted to display certain message on CD after remote events execution gets completed on CM.

Is there anyway i can get notified except watching for EventQueue table status?

3
  • Can you raise another remote event to notify CD server back?
    – Marek Musielak
    Commented Feb 28, 2018 at 10:15
  • No. As i need to display some result to user once CRUD operation gets completed on CM and item is available on web database. It looks like in any case i will have to wait/watch EventQueue or sleep. Commented Feb 28, 2018 at 10:53
  • So as I wrote above, raise event "CRUD COMPLETED" from CM server. And on CD server wait for that event...
    – Marek Musielak
    Commented Feb 28, 2018 at 11:11

2 Answers 2

3

Technically you could run a custom SQL query to see if a server completed execution of a Remote Event, but I wouldn't recommend it.

When you say:

Is there anyway i can get notified except watching for EventQueue table status?

This operation happens automatically when the EventProvider polls the various [EventQueue] tables. Therefore, part of what you need to accomplish is already done for you.

What you need to do

Generally speaking, you need to create a RemoteEvent type (e.g. MyCmEvent), and subscribe to this type on initialization.

Custom Type

[DataContract]
public class MyCmEvent
{
    public MyCmEvent(string instanceName)
    {
        InstanceName = instanceName;
    }

    [DataMember]
    public string InstanceName { get; protected set; }
}

Add type to subscription mapping

public class MyCmEventRemoteMap
{
    public static void Initialize()
    {
        EventManager.Subscribe<MyCmEvent>(new Action<MyCmEvent>(StoreFactRemoteEventRan<MyCmEvent>));
    }

    private static void StoreFactRemoteEventRan<TEvent>(TEvent @event)
    {
        // build your primary logic here to store the fact that this event ran, set property in memory, update an item, whatever fits your needs
    }
}

Config needed

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <pipelines>
            <initialize>
                <processor type="MyNamespace.MyCmEventRemoteMap, MyDll" method="Initialize" />
            </initialize>
        </pipelines>
    </sitecore>
</configuration>

From CM Server

From your CM server, when you need to trigger this code, you would call:

var myCmEvent= new MyCmEvent(Sitecore.Configuration.Settings.InstanceName);
EventManager.QueueEvent<MyCmEvent>(myCmEvent);

The above code will add a record to the System Event Queue, and set it to run globally, i.e. on CD server(s).


Notice in the StoreFactRemoteEventRan method, you need to store the fact that the RemoteEvent executed. However you end up storing this, you will need to read it wherever you want to display the message on your CD servers. I'm making an assumption that you have multiple CD servers, so likely need to store something in the database- either on an item or in the Core DB -> [Properties] table (it's good for this type of thing).

7
  • This is the best possible solution. But unfortunately i would not be able to use that. As against user interaction, i need to acknowledge user immediately. I couldn't perform that operation from remote event handler. Bettee i added wait time there. Commented Feb 28, 2018 at 20:18
  • If you want an action on a CD server to communicate with the CM server, then have the CM server call back you would have a minimum of 4 seconds for the result to be returned- queue from CD, register on CM, queue new event, read on CD. I have played around with a proof of concept that does this, but it's not an ideal scenario. It's possible, but you would definitely need to show the user a loading icon or something as the CD server waits for the required event to be returned from the CM. What is it you're exactly trying to accomplish?
    – jrap
    Commented Feb 28, 2018 at 20:33
  • Basically user is shown a list of items. User can create a new one using form on CD and user should see updated list. Creating items on CM and publishing it. Commented Feb 28, 2018 at 21:23
  • Couldn’t you create the item in web and then transfer it to the master database? This functionality exists in the item transfer command though I have never looked at it. That would provide you with a real-time update
    – jrap
    Commented Mar 1, 2018 at 0:07
  • I tracked down the Item transfer logic. If you're interested, I can create a separate question/answer.
    – jrap
    Commented Mar 1, 2018 at 14:03
-1

The only option left after EventQueue is to use Sitecore ItemWebAPI. You can hit the Get/ReadOnly request to know the status of the item you changes/created in master.

Have a look at this blog http://www.sitecorecoding.com/2016/08/update-item-name-using-sitecore-item.html

Sitecore documentation for ItemWebAPI is available till Sitecore 7.1 and I have used item webApi in Sitecore 7.2.

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.