Try our conversational search powered by Generative AI!

Events from IContentEvents not being raised in a load balanced environment

Vote:
 

We have a singleton service which subscribes to PublishedContent and MovedContent from IContentEvents. And this works as expected locally, when the CMS is running in a single IIS application. When the app is deployed in multiple load balanced IIS applications, we use EPiServer.Azure, which works as expected for propagating changes from CMS like publishing of new pages to every instance. But we are not getting any published or moved content events in the singleton service in this envirnoment. 

example from Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddCms();
    ...
    services.AddSignleton<MyService>();
    ...
    services.AddAzureEventProvider(o =>
    {
        o.ConnectionString = _configuration.GetValue<string>("AzureEventBus:ConnectionString");
        o.TopicName = _configuration.GetValue<string>("AzureEventBus:Topic");
        o.EnablePartitioning = false;
        o.TopicSize = 1024; // 1GB
    });
...

from MyService.cs

public class MyService {
  public NavigationBuilder(IContentEvents contentEvents) {
     contentEvents.PublishedContent += OnContentUpdated;
     contentEvents.MovedContent += OnContentUpdated;
  }

  private void OnContentUpdated(object sender, ContentEventArgs e)
  {
     // do something; gets called on local; never called in load balanced env
  }
}
#313521
Dec 01, 2023 16:08
Vote:
 

I am not sure but I think the content events are only local - they are not raised on remote instances like cache invalidation

#313522
Dec 01, 2023 16:59
Vote:
 

Hi Stepan

Maybe you're not moving the page.

From memory, moved event will only be triggered if you change current parent's parent including moved to wastebasket. The event will not get fired for the children of the page being moved.

#313639
Dec 04, 2023 0:47
Quan Mai - Dec 04, 2023 7:28
I think he said it worked locally. I'm quite sure that the moved event is called on the content being moved, not the parent
Vincent - Dec 04, 2023 9:18
I might have misunderstood that. I thought he said it’s working When the app is deployed in multiple load balanced IIS applications.
Vote:
 

I can confirm the content events are local. If you want to raise/listen to them remotely, you will need something like this episerver/content-events-masstransit (github.com)

#313643
Dec 04, 2023 7:29
Stepan Stanc - Dec 04, 2023 8:46
Thank you, just knowing that they're raised only locally helps. Our problem in the load balanced env actually was that the service never got instantiated for the app where the CMS changes were made, so the service also never invalidated caches for the other load balanced apps. We can solve this now understanding this.

Is this the rule for all events exposed from the CMS that they're only local?
Quan Mai - Dec 04, 2023 9:53
Not exactly a rule but yes they are local by default. Only cache invalidation is remote. I created a bug so the team can improve doc for that
Stepan Stanc - Dec 04, 2023 10:12
Great, and thanks again for the quick feedback
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.