Provides guidance on ABP's local/distributed event bus, background jobs, and background workers for decoupling code, reacting to entity changes, and scheduling deferred/recurring work.
Ships in abp-runtime. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Guidance for the ABP event bus (local + distributed), background jobs, and background workers. All APIs below are verified against ABP source. Inject services via constructor; the event bus only subscribes handlers that are already registered in DI, so a handler class must be registered (e.g. by implementing ITransientDependency or explicit registration) — implementing the handler interface alone is not enough.
IAbpDistributedLock, IDistributedCache<T>).ILocalEventBus (namespace Volo.Abp.EventBus.Local) publishes events within the same process. Publish via the inherited IEventBus.PublishAsync:
public class MyService : ITransientDependency
{
private readonly ILocalEventBus _localEventBus;
public MyService(ILocalEventBus localEventBus) => _localEventBus = localEventBus;
public async Task DoAsync()
{
// onUnitOfWorkComplete defaults to true: published at end of the current UoW
await _localEventBus.PublishAsync(new StockCountChangedEvent { ProductId = 42, NewCount = 10 });
}
}
Handle by implementing ILocalEventHandler<TEvent> (namespace Volo.Abp.EventBus). The handler is only subscribed if its class is registered in DI, so add ITransientDependency (or register it explicitly):
public class StockCountChangedHandler
: ILocalEventHandler<StockCountChangedEvent>, ITransientDependency
{
public Task HandleEventAsync(StockCountChangedEvent eventData)
{
// ...
return Task.CompletedTask;
}
}
A single class can implement multiple ILocalEventHandler<T> interfaces.
ABP resolves each DI-registered handler in a new DI scope and disposes that scope as soon as HandleEventAsync returns. While the handler runs, CurrentTenant is the event's tenant (from IMultiTenant.TenantId when the event carries one), and it is restored when the handler returns. Inside a unit of work both happen before the commit, so an OnCompleted callback the handler registers runs after its scope is gone and in the tenant active when the unit of work completes, not the event's tenant; write it as shown in manage-units-of-work.
ABP automatically publishes local events when entities are created/updated/deleted through a repository. Handle them with the generic event data types from Volo.Abp.Domain.Entities.Events. The changed entity is on the .Entity property:
public class ProductCacheInvalidator
: ILocalEventHandler<EntityCreatedEventData<Product>>,
ILocalEventHandler<EntityUpdatedEventData<Product>>,
ILocalEventHandler<EntityDeletedEventData<Product>>,
ITransientDependency
{
public Task HandleEventAsync(EntityCreatedEventData<Product> e) => Invalidate(e.Entity);
public Task HandleEventAsync(EntityUpdatedEventData<Product> e) => Invalidate(e.Entity);
public Task HandleEventAsync(EntityDeletedEventData<Product> e) => Invalidate(e.Entity);
private Task Invalidate(Product product) => Task.CompletedTask;
}
Hierarchy: EntityCreatedEventData<T>, EntityUpdatedEventData<T>, EntityDeletedEventData<T> all derive from EntityChangedEventData<T>, which exposes TEntity Entity { get; }. Subscribe to EntityChangedEventData<T> to catch all three.
IDistributedEventBus (namespace Volo.Abp.EventBus.Distributed) publishes across processes/microservices through a provider (RabbitMQ, Kafka, Azure Service Bus, Dapr, Rebus, or the default in-memory one). Note the extra useOutbox parameter:
Task PublishAsync<TEvent>(TEvent eventData, bool onUnitOfWorkComplete = true, bool useOutbox = true)
where TEvent : class;
Distributed events are transferred as serializable ETOs (Event Transfer Objects). Give the ETO a stable, transport-level name with [EventName] (namespace Volo.Abp.EventBus) so producer and consumer agree regardless of CLR type name:
[EventName("MyApp.Stock.Changed")]
public class StockChangedEto
{
public Guid ProductId { get; set; }
public int NewCount { get; set; }
}
// publisher
await _distributedEventBus.PublishAsync(new StockChangedEto { ProductId = id, NewCount = count });
Handle with IDistributedEventHandler<TEto> (namespace Volo.Abp.EventBus.Distributed):
public class StockChangedHandler
: IDistributedEventHandler<StockChangedEto>, ITransientDependency
{
public Task HandleEventAsync(StockChangedEto eventData) => Task.CompletedTask;
}
Provider selection is a module + configuration concern (e.g. AbpEventBusRabbitMqModule, AbpEventBusKafkaModule) plus settings in appsettings.json. Keep useOutbox/inbox enabled for reliable, transactional delivery when the provider is configured for it.
Use IBackgroundJobManager (namespace Volo.Abp.BackgroundJobs) to queue work that runs later, retried on failure:
Task<string> EnqueueAsync<TArgs>(
TArgs args,
BackgroundJobPriority priority = BackgroundJobPriority.Normal,
TimeSpan? delay = null);
await _backgroundJobManager.EnqueueAsync(
new EmailSendingArgs { To = "[email protected]", Subject = "Hi" },
delay: TimeSpan.FromSeconds(30));
BackgroundJobPriority values: Low, BelowNormal, Normal (default), AboveNormal, High.
Define the job by deriving from AsyncBackgroundJob<TArgs> (implements IAsyncBackgroundJob<TArgs>) and overriding ExecuteAsync. The args type is how the job is looked up.
public class EmailSendingJob : AsyncBackgroundJob<EmailSendingArgs>, ITransientDependency
{
public override async Task ExecuteAsync(EmailSendingArgs args)
{
// send email; a Logger property is available from the base class
}
}
For synchronous jobs, derive from BackgroundJob<TArgs> (IBackgroundJob<TArgs>) and override void Execute(TArgs args). Prefer the async version. The startup template ships the Background Jobs module, which persists jobs in the database by default (so they survive restarts and are retried); the framework only falls back to an in-memory store when no persistent job-store module is installed. Hangfire, Quartz, and RabbitMQ are alternative providers you can swap in — not a requirement for production.
When the job type isn't known at compile time (plugin systems, dynamic workflows), use IDynamicBackgroundJobManager (namespace Volo.Abp.BackgroundJobs) to enqueue by job name:
// enqueue a typed job (named with [BackgroundJobName("emails")]) by its name
await _dynamicJobManager.EnqueueAsync("emails", new { To = "[email protected]", Subject = "Hi" });
// or register a handler at runtime and enqueue against it
_dynamicJobManager.RegisterHandler("ProcessOrder", async (context, ct) => { /* ... */ });
await _dynamicJobManager.EnqueueAsync("ProcessOrder", new { OrderId = orderId });
EnqueueAsync(name, args) looks up the job by [BackgroundJobName] (or a runtime-registered handler), deserializes the args, and runs through the same persistent pipeline as typed jobs. Use typed IBackgroundJobManager when the job type is known; reach for the dynamic manager only when it genuinely isn't (the args are loosely typed, so you lose compile-time checking).
For periodic loops, derive from AsyncPeriodicBackgroundWorkerBase (namespace Volo.Abp.BackgroundWorkers). Its constructor takes AbpAsyncTimer timer and IServiceScopeFactory serviceScopeFactory; set timer.Period (milliseconds) and override DoWorkAsync. Each run gets a fresh DI scope via workerContext.ServiceProvider — resolve scoped services from there, not the constructor:
public class CleanupWorker : AsyncPeriodicBackgroundWorkerBase
{
public CleanupWorker(AbpAsyncTimer timer, IServiceScopeFactory scopeFactory)
: base(timer, scopeFactory)
{
Timer.Period = 60_000; // every 60s
}
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
var repo = workerContext.ServiceProvider
.GetRequiredService<IRepository<StaleRecord, Guid>>();
// ... do periodic work
}
}
AsyncPeriodicBackgroundWorkerBase also exposes a CronExpression property, but the default in-memory worker only schedules by Period — its AbpAsyncTimer ignores CronExpression. Cron scheduling is honored only when you use a Hangfire, Quartz, or TickerQ background-worker provider.
Register the worker in your module's OnApplicationInitializationAsync with the extension AddBackgroundWorkerAsync<TWorker> on ApplicationInitializationContext:
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{
await context.AddBackgroundWorkerAsync<CleanupWorker>();
}
To add a worker at runtime, resolve IBackgroundWorkerManager and call AddAsync(IBackgroundWorker worker). Custom workers can also derive from BackgroundWorkerBase (which implements IBackgroundWorker) for full control.
[EventName] + ETO.Each provider needs its [DependsOn] module. The configuration shape differs per provider — some use Configure<...Options>, some PreConfigure<...>, and some also need an initialization-phase call (see the note below the examples). appsettings.json config works too, and values set in code take precedence over it.
Hangfire — depend on AbpBackgroundJobsHangfireModule and wire a Hangfire storage/server in ConfigureServices (Hangfire has no ABP options class; you configure Hangfire itself):
[DependsOn(typeof(AbpBackgroundJobsHangfireModule))]
public class MyModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
context.Services.AddHangfire(config =>
config.UseSqlServerStorage(configuration.GetConnectionString("Default")));
}
}
RabbitMQ — depend on AbpBackgroundJobsRabbitMqModule; connections come from the RabbitMQ:Connections config (default = localhost), and AbpRabbitMqBackgroundJobOptions customizes queue names/connections per job:
Configure<AbpRabbitMqBackgroundJobOptions>(options =>
{
options.DefaultQueueNamePrefix = "my_app_jobs.";
options.JobQueues[typeof(EmailSendingArgs)] = new JobQueueConfiguration(
typeof(EmailSendingArgs),
queueName: "my_app_jobs.emails",
delayedQueueName: "my_app_jobs.emails.delayed", // required ctor arg
connectionName: "Default");
});
Swap the default in-memory worker timer for a provider that honors CronExpression — but the two mainstream providers are not both zero-config:
AbpBackgroundWorkersHangfireModule) needs a Hangfire storage/server configured, exactly like the Hangfire job provider above (AddHangfire(config => config.UseSqlServerStorage(...))). The module adapts your workers but does not pick or configure storage — without it Hangfire fails to start.AbpBackgroundWorkersQuartzModule) runs on Quartz's default in-memory (RAM) store with no options; for production, configure a persistent Quartz store.[DependsOn(typeof(AbpBackgroundWorkersQuartzModule))] // Quartz: in-memory store by default
// or AbpBackgroundWorkersHangfireModule — then also configure Hangfire storage (see the Hangfire job example above)
public class MyModule : AbpModule { }
Your existing AsyncPeriodicBackgroundWorkerBase workers, registered the same way with context.AddBackgroundWorkerAsync<TWorker>(), are then dispatched by the chosen provider (Hangfire adapts them via HangfirePeriodicBackgroundWorkerAdapter). This is what makes CronExpression honored on Quartz/Hangfire/TickerQ, unlike the default in-memory timer.
RabbitMQ — depend on AbpEventBusRabbitMqModule; AbpRabbitMqEventBusOptions sets ConnectionName, ClientName (the queue name for this app), and ExchangeName:
[DependsOn(typeof(AbpEventBusRabbitMqModule))]
public class MyModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpRabbitMqEventBusOptions>(options =>
{
options.ClientName = "MyApp";
options.ExchangeName = "MyMessages";
});
}
}
Kafka — depend on AbpEventBusKafkaModule; AbpKafkaEventBusOptions sets ConnectionName, GroupId (consumer group), and TopicName:
[DependsOn(typeof(AbpEventBusKafkaModule))]
public class MyModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpKafkaEventBusOptions>(options =>
{
options.GroupId = "MyGroupId";
options.TopicName = "MyTopicName";
});
}
}
The other providers (Quartz/TickerQ for jobs, Azure Service Bus/Rebus for the event bus) each add their [DependsOn] module, but the configuration shape is not uniform — check each provider's doc:
PreConfigureServices via PreConfigure<AbpRebusEventBusOptions>(...), not Configure.context.GetHost().UseAbpTickerQ() in OnApplicationInitialization (the UseAbpTickerQ extension is on IHost, not the context), not just options.PreConfigure<AbpQuartzOptions>(...) for the scheduler plus Configure<AbpBackgroundJobQuartzOptions>(...) for the job integration.ITransientDependency or is registered explicitly) — an unregistered handler is silently never invoked.context.AddBackgroundWorkerAsync<TWorker>() and observe DoWorkAsync firing on the configured Timer.Period (or the CronExpression, only if you run a Hangfire/Quartz/TickerQ provider).ExecuteAsync runs after the configured delay (with a persistent provider wired in for anything beyond dev).ITransientDependency or register the class explicitly, or it never fires.OnCompleted callback runs after the handler's scope is disposed and does not keep the event's tenant; pass it plain values and follow the callback pattern in manage-units-of-work.DoWorkAsync run gets a fresh scope; resolve scoped services from workerContext.ServiceProvider, not the constructor.[EventName] on the ETO, or delivery breaks when type names differ across services.IBackgroundJobStore is installed. The startup template already installs the module with a database store (per your ORM), which is production-usable; Hangfire/Quartz/RabbitMQ are optional alternative providers, not a requirement. In a cluster, still configure a distributed lock so jobs execute on one instance.useOutbox/inbox enabled (with a provider configured for it) for transactional delivery.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
abp, event-bus, background-jobs, background-workers, distributed-events
/abp-runtime:background-jobs-and-eventsfrom abp-runtime
npx claudepluginhub abpframework/abp-skills --plugin abp-runtime10 skills in this plugin
/cache-entitiesRead-only single-entity-by-id caching via the generic IEntityCache abstraction (cache to the entity or a DTO), auto-invalidated. USE FOR: AddEntityCache, caching to entity or DTO, batch lookups (FindMany/GetMany), expiration, EntityCacheWithObjectMapper mapping. DO NOT USE FOR: general key/value caching or distributed locks (distributed-caching-and-locking); querying/persisting entities (ef-core-integration or mongodb-integration)./configure-app-urlsNamed application roots and external URLs with AppUrlOptions, resolved tenant-aware via IAppUrlProvider. USE FOR: AppUrlOptions.Applications; RootUrl and named Urls; email links; cross-application links; tenantId and tenantName placeholders; redirect allow-list checks. DO NOT USE FOR: rendering the email body (render-text-templates) or sending it (send-emails); remote service base addresses (consume-remote-services); resolving tenants by domain (configure-multi-tenancy)./configure-production-hostingRelease checklist for hosting an ABP app in production behind a reverse proxy or clustered. USE FOR: forwarded headers, shared Data Protection keys, cluster cache/lock, single/multi-instance jobs/workers, SignalR scale-out, shared KeyPrefix. DO NOT USE FOR: the cache/lock APIs (distributed-caching-and-locking); job/worker mechanics (background-jobs-and-events); SignalR hubs (add-signalr-realtime); OpenIddict prod certs (configure-openiddict-authentication)./distributed-caching-and-lockingTyped distributed caching and cross-instance distributed locking. USE FOR: typed IDistributedCache / GetOrAddAsync (Redis-backed), IAbpDistributedLock.TryAcquireAsync, AbpDistributedCacheOptions / [CacheName]. DO NOT USE FOR: per-entity caching (cache-entities); multi-tier hybrid cache (use-hybrid-caching); events, background jobs, or workers (background-jobs-and-events); settings/features (manage-settings-and-features); data filters (apply-data-filters)./render-text-templatesRender text templates (Scriban or Razor) in ABP. USE FOR: TemplateDefinitionProvider, TemplateDefinition + WithScribanEngine/WithRazorEngine, WithVirtualFilePath content, ITemplateRenderer.RenderAsync, per-culture localization, layouts, the Razor safety boundary. DO NOT USE FOR: sending the rendered body as email (send-emails); embedding .tpl files (manage-virtual-files); localization resources (localize-applications)./secure-web-requestsABP ASP.NET Core CSRF protection and response security headers. USE FOR: AbpAntiForgeryOptions and antiforgery cookies; MVC antiforgery validation; IAbpAntiForgeryManager; Blazor/WebAssembly antiforgery; AbpSecurityHeadersOptions; UseAbpSecurityHeaders; CSP and script nonces. DO NOT USE FOR: token issuance/API auth (configure-openiddict-authentication); permissions (permissions-and-authorization); MVC/Razor pages (mvc-razor-ui); Blazor components (blazor-ui).Other plugins' skills for the same job