1

what is the difference between normal event and remote events ? And when to customize the remote one ? Can someone please help me understand this with a practical scenario ?

for e.g.

  • name="item:created"
  • name="item:created:remote"
  • name="item:cloneAdded"
  • name="item:cloneAdded:remote"

3 Answers 3

3

Here is something about the events and remote events in Sitecore.

What is an Event?

Events in Sitecore are similar to events in other systems: something triggers an event and there are handlers that are configured to handle the event.

Event handlers are similar to pipelines in how they are configured. An event handler is a .NET class that implements a method. When an event is triggered, the event handlers are run in order.

Event handlers are defined in Sitecore patch files.

The following is an example of the event handler that handles the item:deleted event.

<event name="item:deleted">
  <handler type="Sitecore.Links.ItemEventHandler, Sitecore.Kernel" 
           method="OnItemDeleted" />
  <handler type="Sitecore.Tasks.ItemEventHandler, Sitecore.Kernel" 
           method="OnItemDeleted" />
  <handler type="Sitecore.Globalization.ItemEventHandler, Sitecore.Kernel" 
           method="OnItemDeleted" />
  <handler type="Sitecore.Data.Fields.ItemEventHandler, Sitecore.Kernel" 
           method="OnItemDeleted" />
  <handler type="Sitecore.Rules.ItemEventHandler, Sitecore.Kernel" 
           method="OnItemDeleted" />
</event>

What is a Remote Event?

When an event is triggered, the event handlers on that server run. For example, when an item is saved, the item:saved event is fired on that server. That causes the database to be updated and for the cache to be updated.

But what happens if you are using a multi-server environment? The database has already been updated, so that doesn’t need to happen again. But the item may be cached on the other servers, so the cache needs to be updated. This is what remote events do. They ensure the appropriate handlers are run on remote servers.

The following is an example of the remote event handler for the item:deleted event. Another way of describing the following is it is an example of the event handlers for the remote:item:deleted event.

<event name="item:deleted:remote">
  <handler type="Sitecore.Globalization.ItemEventHandler, Sitecore.Kernel" 
                  method="OnItemDeletedRemote" />
  <handler type="Sitecore.Data.Fields.ItemEventHandler, Sitecore.Kernel" 
                  method="OnItemDeletedRemote" />
  <handler type="Sitecore.Rules.ItemEventHandler, Sitecore.Kernel" 
                  method="OnItemDeletedRemote" />
</event>

If your event requires a remote event be triggered on remote servers, you need to be sure that you raise the remote event.

In a multi-server Sitecore environment, the term “remote” describes each of the other servers in the environment. It is a relative designation. Remote servers are all of the servers in the environment except for the server that the code is currently running on.

And here are some code snippets that you can use for this: https://sitecore-community.github.io/docs/pipelines-and-events/events/#event_basics

2

In a scaled environment where you have a CM and 1 or more CD instances, events can happen locally (normal) or remotely. So the thing that causes the event will raise the event local to the instance it occurs on, then the event system will also raise that event remotely so that the other instances can respond to it.

For example, take the publish:end event.

Publishing happens on your CM instance, when the publishing is complete, the CM will raise a publish:end event on the CM instance. You can use this to add custom actions etc...

At the same time, it will use the event queue to raise publish:end:remote events, the CD instances will receive these and you can use those to perform some action. OOTB, Sitecore XM/XP uses these events to clear caches on the CD instances when publishing is complete.

1
  • Thanks @Rishard. So I am now overriding "item:cloneAdded" event and its working fine in local. Do I need to write same code for "item:cloneAdded:remote" to make them work higher environments ? Commented Dec 29, 2022 at 16:25
1

Sitecore has a useful feature where custom methods can be triggered on various events, such as item creation, saving, publishing, deletion etc.

:remote events are fired on your remote (content delivery) servers.

The publish:end and publish:end:remote events are the 2 most obvious choices. event to clear the cache whenever an item was published. publish:end and publish:end:remote is fired, when the current publish operation is completed.

Check this link for practical use: https://www.velir.com/ideas/2017/08/01/remote-vs-local-custom-publishing-events-in-sitecore

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.