Configuration
Both sets of options are standard .NET options (IOptions<MassiveJobsOptions>, IOptions<RabbitMqOptions>): set them in
code, bind them from configuration, or both. They’re validated when MassiveJobs starts; invalid options stop the host from
starting.
builder.Services.AddMassiveJobs(o => { o.NamePrefix = "shop."; o.MaxDegreeOfParallelismPerWorker = 4; }) .WithJobsFromAssemblyOf<Program>() .UseRabbitMq(o => o.ConnectionString = builder.Configuration.GetConnectionString("RabbitMq"));From configuration
Section titled “From configuration”builder.Services.AddOptions<MassiveJobsOptions>().BindConfiguration("MassiveJobs");builder.Services.AddOptions<RabbitMqOptions>().BindConfiguration("RabbitMq");{ "MassiveJobs": { "NamePrefix": "shop.", "MaxDegreeOfParallelismPerWorker": 4, "ShutdownTimeout": "00:00:45" }, "RabbitMq": { "ConnectionString": "amqps://shop:secret@rabbit.example.com/shop" }}BindConfiguration comes from Microsoft.Extensions.Options.ConfigurationExtensions, which ASP.NET Core and worker
service apps already have. MassiveJobs itself doesn’t depend on configuration.
MassiveJobsOptions
Section titled “MassiveJobsOptions”Options marked shared must be the same in every app that shares the jobs.
| Option | Default | |
|---|---|---|
NamePrefix |
"" |
Prefix of the queue and exchange names. Shared. |
StartWorkers |
true |
Whether this app runs workers. false for an app that only publishes. |
ImmediateWorkersCount |
4 |
Immediate queues, each with a worker in every app that runs workers. Shared. |
LongRunningWorkersCount |
2 |
Long-running queues. Shared. |
MaxDegreeOfParallelismPerWorker |
1 |
Jobs a worker runs at once (at most 65,535). |
BatchSize |
0 (250) |
Messages an immediate worker holds unacknowledged (the prefetch). |
PublishBatchSize |
100 |
The most messages sent in one call when publishing many jobs. |
MaxQueueLength |
50,000 |
The most messages a queue holds; publishing to a full queue fails. QueueLength.NoLimit (-1) for none. |
MaxRetries |
25 |
Retries of a failed job before the failed queue. 0: none. [JobRetry] on a job class sets its own. |
LongRunningThreshold |
10 s |
Jobs published with at least this timeout go to the long-running queues. |
ShutdownTimeout |
20 s |
How long running jobs get to finish when the app stops. |
UnknownJobTimeout |
30 min |
How long a job with a tag no app knows is delayed before the failed queue. |
PeriodicSeedInterval |
1 min |
How often each app checks that the next run of each of its periodic jobs is in the broker. |
JsonTypeInfoResolver |
null |
System.Text.Json metadata for the jobs’ arguments, e.g. a JsonSerializerContext. Needed under trimming and Native AOT. |
The queue names are read-only properties: ImmediateQueueNameTemplate, LongRunningQueueNameTemplate,
PeriodicQueueName, FailedQueueName.
RabbitMqOptions
Section titled “RabbitMqOptions”Set either ConnectionString or the connection properties, not both. Without either, MassiveJobs connects to localhost as
guest.
| Option | Default | |
|---|---|---|
ConnectionString |
An AMQP URI: amqp://user:password@host:port/vhost, amqps:// for TLS. Percent-encode special characters; the default vhost / is %2F, or left out. |
|
HostNames |
localhost |
The nodes, tried in order until one accepts the connection. |
Port |
-1 |
5672, or 5671 with TLS. |
VirtualHost |
/ |
|
Username, Password |
guest |
RabbitMQ accepts guest only from localhost. |
SslEnabled |
false |
|
SslServerName |
the host name | The name the server’s certificate must have. |
SslClientCertPath, SslClientCertPassPhrase |
A client certificate, for TLS with client authentication. |
The prefetch count is MassiveJobsOptions.BatchSize. See RabbitMQ for what MassiveJobs declares on the
broker.
Other services
Section titled “Other services”AddMassiveJobs registers its services with TryAdd, so you can replace them by registering your own first. The one
worth knowing is TimeProvider: MassiveJobs reads the clock and waits only through it, which is how
tests run scheduled jobs on fake time.