Skip to content

Configuration ​

Everything is set up in one place: the store, the handlers and the settings. The defaults suit desktop apps, web apps and workers alike, so most apps only choose a store and add their handlers:

csharp
builder.Services.AddPulseSharp(pulse =>
{
    pulse.UseSqlite("app.db");

    pulse.Node = "till-1";
    pulse.MaxAttempts = 5;
    pulse.RetryDelay = TimeSpan.FromSeconds(1);

    pulse.AddHandler<SaleCompleted, PrintReceipt>();
    pulse.AddJobHandler<ExportReport, ExportReportHandler>();
});

Settings ​

SettingDefaultMeaning
Nodemachine nameThe name of this app instance, stored with every event it emits
MaxAttempts5Attempts per event (per handler) or job before it fails
RetryDelay1 secondWait before the first retry; doubles each time, up to 5 minutes

Advanced settings ​

You rarely need these. They live under pulse.Advanced so the everyday settings stay easy to find.

SettingDefaultMeaning
PollInterval1 secondHow often handlers and workers check for work when nothing wakes them. Also the heartbeat that renews the claims on handlers and running jobs: after a crash, a handler is taken over after 10 poll intervals (at least 10 seconds) and a job after 30 (at least 30 seconds)
MaxParallelStreams8Streams one handler works on at the same time
MaxParallelJobs4Jobs this app instance runs at the same time
KeepFinishedJobs7 daysHow long to keep jobs that succeeded or were cancelled. Failed jobs are kept until retried. null keeps every job
HandlerTimeout5 minutesHow long one handler may take for one event. Then it is cancelled, and abandoned if it does not stop within 10 poll intervals. The attempt counts as failed and is retried. null sets no limit
JobTimeout1 hourThe same for one run of a job. null sets no limit
JsonOptionsweb defaultsHow events and jobs are stored as JSON. Set a source-generated resolver for Native AOT - see Stores

Stores ​

Choose one inside AddPulseSharp(pulse => …):

MethodStore
UseSqlite("app.db")SQLite file (a file name or a full connection string) - durable, for desktop, mobile and small servers (PulseSharp.Sqlite). See Stores
UsePostgreSql(connectionString, schema)PostgreSQL, several app instances (PulseSharp.PostgreSql, schema pulsesharp by default). See Stores
UseStore(store)Your own IPulseStore implementation

For tests, PulseSharp.Testing adds UseInMemory(), a store that keeps everything in memory. See Testing.

Handlers ​

MethodAdds
On<TEvent>(name, handler)An inline event handler: async (sale, context, ct) => …, with a name you choose
AddHandler<TEvent, THandler>()An event handler class, created from dependency injection
OnJob<TJob>(handler)The inline handler of a job type: async (job, context, ct) => …
AddJobHandler<TJob, THandler>()The handler class of a job type

All four work with trimming and Native AOT.

Startup checks ​

When everything is fine, PulseSharp logs one line at startup, for example PulseSharp is ready. Store: SqliteStore, node: till-1, event handlers: 2, job types: 1.

It refuses to start - with a message that says what to fix - when:

  • no store is chosen,
  • two handlers share a name, or two event types or two job types share a name,
  • a job type has two handlers,
  • a setting is out of range,
  • AddPulseSharp is called twice.

Registered services ​

ServiceUse it to
IPulseEmit events and enqueue jobs
IPulseControlRead cursors and jobs; retry, skip, rewind, cancel

Both are singletons; inject them anywhere.

Released under the MIT License.