9

What is the difference between Sitecore Pipelines and a Sitecore Event Handlers for a specific event? When should we customise a pipeline and when should we add a new handler?

9

Pipeline

To me pipelines are about process. Do this, then this. Allowing you to insert and remove processes simply with patch configs. A great example of this is login user pipeline. Your pipeline would be:

  1. Log user in
  2. Identify user in xDB
  3. Add logging info for user
  4. Add user to marketing automation for returning customer
  5. etc....

It is a process flow that you can reorder and add to/subtract from.

Event

Events are one off, very focused actions. Like item:saved vs item:saving. item:renamed vs item:duplicated. They are extremely focused. Although you could tie many events together in the config, they are not very process oriented. It is more about data manipulation than process.

  • 1
    Remember that you could also run a pipeline in your event handler :) – Richard Seal Oct 30 '18 at 18:58
  • Thank you. This helped clarify my understanding of pipelines and event handlers :) – Shubham Bassi Oct 30 '18 at 19:06
4

To add to @Chris Auer, think of it this way:

What is the difference

An event is a reaction to something happening in the system. This could be a user interaction, like item:saved, item:created, etc, or it could be raised by another process in the system like publish:end or publish:end:remote. And there can be many handlers for a single event, just look at some of the item: events and how many handlers SXA adds to them.

The key point here is that an event reacts to something else being done in the platform.

A pipeline requires something to start that process, but as Chris mentioned, the pipeline is a pattern that starts with some data and then sends that data through various processors to consume, manipulate or add to that data. So you might think of mvc.getPageItem pipeline; that pipeline takes the initial data about the page context and each processor does something with that data, from setting the language, trying different methods to resolve the page item to hooking into the Content Testing module.

The key for pipelines is that it's processing data.

When should I use event handlers/pipelines

Now we have the distinction, it should be fairly easy to know what you want to use.

If you want to react to an existing event that occurs in the system, you probably want to create an event handler. It is important to remember that hooking into some of the item event handlers can seriously affect your editor performance. You should make sure the code is as performant as you can get it. Don't take shortcuts just because it won't affect the delivery of the site.

As for pipelines, its unusual to create a completely custom pipeline, although it does happen. More often you are hooking into an existing pipeline and adding a processor there. So if you find that you need to change the way something in Sitecore functions, say for example you want to extend the source property on a TreeList, then you would be creating a pipeline processor to do that.

Your Answer

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

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