Skip to content

Instantly share code, notes, and snippets.

@hishaamn
Created March 14, 2025 18:21
Show Gist options
  • Save hishaamn/cee9ebb782483d161eb343a4533a9168 to your computer and use it in GitHub Desktop.
Save hishaamn/cee9ebb782483d161eb343a4533a9168 to your computer and use it in GitHub Desktop.
Updated InitializeBuses class with single constructor
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Sitecore.Diagnostics;
using Sitecore.Events;
using Sitecore.Messaging;
using Sitecore.Messaging.Events;
using Sitecore.Pipelines;
public class InitializeBuses
{
private readonly IMessageBusStarter _busStarter;
public InitializeBuses(IMessageBusStarter busStarter)
{
_busStarter = busStarter ?? throw new ArgumentNullException(nameof(busStarter));
}
public void Process(PipelineArgs args)
{
Dictionary<string, bool> busStartResults = new Dictionary<string, bool>();
_busStarter.Start(
busName =>
{
busStartResults.Add(busName, true);
Log.Info($"Messaging: IMessageBus started successfully: '{busName}'", this);
Event.RaiseEvent("messaging:busstarted", new MessageBusInitializedEventArgs(busName, true));
},
(busName, ex) =>
{
busStartResults.Add(busName, false);
Log.Error($"Messaging: IMessageBus failed to start '{busName}'.", ex, this);
Event.RaiseEvent("messaging:busstarted", new MessageBusInitializedEventArgs(busName, false));
}
).ContinueWith(t =>
Event.RaiseEvent("messaging:allBusesInitialized", new AllMessageBusesInitializedEventArgs(busStartResults)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment