Identify which database raised a publish event
Current version: 10.3
Knowing which database raised a publish:end
or a publish:end:remote
event can be very useful when you want to update the caches on, for example, remote Sitecore CD instances.
To identify the database that raised a publish:end
event, run this code:
RequestResponse
Public void OnPublishEnd(object sender, EventArgs args)
{
var Publisher publisher =
Sitecore.Events.Event.ExtractParameter<Publisher>(args,
0) as Publisher;
var db = publisher.Options.TargetDatabase.Name;
}
To identify the database that raised a publish:end:remote
event, run this code:
RequestResponse
Public void OnPublishEndRemote(object sender, EventArgs args)
{
var publishEndArgs = args as Sitecore.Data.Events.PublishEndRemoteEventArgs;
var dbs =
Sitecore.Configuration.Factory.GetDatabases().Where(db =>
db.RemoteEvents.EventQueue.Name == publishEndArgs.EventQueueName);
}