zb-client-bootstrap
0.0.1
See the version list below for details.
dotnet add package zb-client-bootstrap --version 0.0.1
NuGet\Install-Package zb-client-bootstrap -Version 0.0.1
<PackageReference Include="zb-client-bootstrap" Version="0.0.1" />
paket add zb-client-bootstrap --version 0.0.1
#r "nuget: zb-client-bootstrap, 0.0.1"
// Install zb-client-bootstrap as a Cake Addin #addin nuget:?package=zb-client-bootstrap&version=0.0.1 // Install zb-client-bootstrap as a Cake Tool #tool nuget:?package=zb-client-bootstrap&version=0.0.1
Boostrap extension for the C# Zeebe client
This project is an extension of the C# Zeebe client project. Zeebe Job handlers are automaticly recognized and boostrapped via a .Net HostedService.
Requirements
- .Net 5.0
- latest C# Zeebe client release
- latest Zeebe release
How to use
The Zeebe C# client boostrap extensions is available via nuget (https://www.nuget.org/packages/zb-client-bootstrap/).
See examples for more information.
Quick start
All classes which implement IJobHandler<T>
or IAsyncJobHandler<T>
are automaticly found and boostrapped when you register this boostrap project with the IServiceCollection
extension method BoostrapZeebe
.
The BoostrapZeebe
method has two parameters:
ZeebeBootstrapOptions
via Configuration, Action delegate or both.- An array with assembly filters, only assemblies which start with one of the filters will be scanned for job handlers.
Appsettings configuration
ConfigureServices((hostContext, services) => {
services.BootstrapZeebe(
hostContext.Configuration.GetSection("ZeebeBootstrap"),
"SimpleExample"
);
})
appsettings.json
{
"ZeebeBootstrap": {
"Client": {
"GatewayAddress": "120.0.0.1:26500"
},
"Worker": {
"MaxJobsActive": 1,
"TimeoutInMilliseconds": 500,
"PollIntervalInMilliseconds": 10000,
"PollingTimeoutInMilliseconds": 30000
}
}
}
Delegate configuration
ConfigureServices((hostContext, services) => {
services.BootstrapZeebe(
options => {
options => {
options.Client = new ClientOptions() {
GatewayAddress = "127.0.0.1:26500"
};
options.Worker = new WorkerOptions()
{
MaxJobsActive = 1,
TimeoutInMilliseconds = 10000,
PollIntervalInMilliseconds = 30000,
PollingTimeoutInMilliseconds = 1000
};
}
},
"SimpleExample"
);
})
Job
The job is an implementation of AbstractJob
. A job can be configured via optional attributes. Job types must be unique.
[JobType("SimpleJobV2")]
[WorkerName("SimpleWorker")]
[MaxJobsActive(2)]
[Timeout(500)]
[PollInterval(10000)]
[PollingTimeout(500)]
class SimpleJob : AbstractJob
{
public SimpleJob(IJob job)
: base(job)
{ }
class JobKeyIsOddException : AbstractJobException
{
public JobKeyIsOddException()
: base("1", "Job key is odd.")
{ }
}
}
class AnotherSimpleJob : AbstractJob
{
public AnotherSimpleJob(IJob job)
: base(job)
{ }
class Response
{
public bool Property { get; set; }
}
}
Job handler
The job handler is an implementation of IJobHandler<Job, Respone>
or IAsyncJobHandler<Job, Response>
. A jobhandler can be configured via optional attributes. Job handlers are automaticly added to the DI container, therefore you can use dependency injection inside the job handlers.
A handled job has three outcomes:
- The job has been handled without exceptions: this will automaticly result in a
JobCompletedCommand
beeing send to the broker. TheResponse
is automaticly serialized and added to theJobCompletedCommand
. - An exception has been thrown while handling the job, the exception implements
AbstractJobException
: this wil automaticly result in aThrowErrorCommand
beeing send to the broker; - Any other exception will automaticly result in a
FailCommand
beeing send to the broker;
[ServiceLifetime(ServiceLifetime.Singleton)]
class SimpleJobHandler : IAsyncJobHandler<SimpleJob>, IAsyncJobHandler<AnotherSimpleJob, AnotherSimpleJob.Response>,
{
public Task HandleJob(SimpleJob job, CancellationToken cancellationToken)
{
if(job.Key % 2 == 0)
{
//Outcome 1 with no response:
return Task.CompletedTask;
}
else
{
//Outcome 2:
return Task.FromException(new SimpleJob.JobKeyIsOddException());
}
}
public Task<AnotherSimpleJob.Response> HandleJob(AnotherSimpleJob job, CancellationToken cancellationToken)
{
if(job.Key % 2 == 0)
{
//Outcome 1 with response:
return Task.FromResult
(
new AnotherSimpleJob.Response()
{
Property = true
}
);
}
else
{
//Outcome 3:
throw new Exception("something unexpected has happened");
}
}
}
Conventions
This project uses the following conventions:
- By default the simple name of the
AbstractJob
implementation is used to match theType
which is specified in the BPMN model. This can be overriden by adding theJobTypeAttribute
to theAbstractJob
implementation. - By default the assembly name which contains the job handler is used as the
Worker name
. This can be overriden by adding theWorkerNameAttribute
to theAbstractJob
implementation. - By default the job handlers are added to de DI container with a
Transient
service lifetime. This can be overriden by adding theServiceLifetimeAttribute
to the job handler. - By default the
ZeebeVariablesSerializer
is registered as the implementation forIZeebeVariablesSerializer
which usesSystem.Text.Json.JsonSerializer
. You can override this registration by registering your service after theBootstrapZeebe
method or you can registerSystem.Text.Json.JsonSerializerOptions
to configure theSystem.Text.Json.JsonSerializer
.
How to build
Run dotnet build Zeebe.Client.Bootstrap.sln
How to test
Run dotnet test Zeebe.Client.Bootstrap.sln
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- Microsoft.Extensions.Configuration.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Hosting (>= 5.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
- zb-client (>= 1.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 11,274 | 9/21/2022 |
0.1.5 | 3,883 | 7/29/2022 |
0.1.4 | 423 | 7/29/2022 |
0.1.3 | 16,609 | 2/12/2022 |
0.1.2 | 532 | 2/2/2022 |
0.1.1 | 1,348 | 12/1/2021 |
0.1.0 | 363 | 11/17/2021 |
0.0.8 | 7,598 | 10/24/2021 |
0.0.7 | 318 | 10/21/2021 |
0.0.6 | 364 | 10/12/2021 |
0.0.5 | 325 | 10/12/2021 |
0.0.4 | 318 | 9/29/2021 |
0.0.3 | 336 | 9/6/2021 |
0.0.2 | 351 | 9/3/2021 |
0.0.1 | 326 | 9/2/2021 |
0.0.1-preview010 | 212 | 8/25/2021 |
0.0.1-preview007 | 211 | 8/25/2021 |
0.0.1-preview006 | 214 | 8/25/2021 |
0.0.1-preview005 | 221 | 8/23/2021 |