zb-client-bootstrap
1.0.0
dotnet add package zb-client-bootstrap --version 1.0.0
NuGet\Install-Package zb-client-bootstrap -Version 1.0.0
<PackageReference Include="zb-client-bootstrap" Version="1.0.0" />
<PackageVersion Include="zb-client-bootstrap" Version="1.0.0" />
<PackageReference Include="zb-client-bootstrap" />
paket add zb-client-bootstrap --version 1.0.0
#r "nuget: zb-client-bootstrap, 1.0.0"
#:package zb-client-bootstrap@1.0.0
#addin nuget:?package=zb-client-bootstrap&version=1.0.0
#tool nuget:?package=zb-client-bootstrap&version=1.0.0
Bootstrap extension for the C# Zeebe client
This project is an extension of the C# Zeebe client project. Zeebe Job handlers are automaticly recognized and bootstrapped via a .Net HostedService.
Read the Zeebe documentation for more information about the Zeebe project.
Requirements
- net standard 2.0 or higher, which means
- .net core 2.1 or higher
- or .net framework 4.7.1 or higher
- latest C# Zeebe client release
- latest Zeebe release
How to use
The Zeebe C# client bootstrap extension is available via nuget (https://www.nuget.org/packages/zb-client-bootstrap/).
See examples and blog post for more information.
Quick start
All classes which implement IJobHandler<TJob>, IJobHandler<TJob, TResponse>, IAsyncJobHandler<TJob> or IAsyncJobHandler<TJob, TResponse> are automaticly found, added to the service collection and autowired to Zeebe when you register this bootstrap project with the IServiceCollection.BootstrapZeebe() extension method.
The BootstrapZeebe method has two parameters:
ZeebeBootstrapOptionsvia configuration, action delegate or both.- An array with assemblies which will be scanned for job handlers.
ConfigureServices((hostContext, services) => {
services.BootstrapZeebe(
hostContext.Configuration.GetSection("ZeebeBootstrap"),
this.GetType().Assembly
);
})
Job
The job is an implementation of AbstractJob. By default the simple name of the job is mapped to BPMN task job type. Job types must be unique. The default job configuration can be overwritten with AbstractJobAttribute implementations, see attributes for more information.
public class SimpleJob : AbstractJob
{
public SimpleJob(IJob job)
: base(job)
{
//Variable mapping logic can be added here.
}
}
There is also a generic version AbstractJob<TState> which will automaticly deserialize job variables into a typed object. Each property is automaticly added to the FetchVariables collection when the FetchVariablesAttribute is not used.
public class SimpleJob : AbstractJob<SimpleJobState>
{
public SimpleJob(IJob job, SimpleJobState state)
: base(job, state)
{ }
}
public class SimpleJobState
{
public bool Test { get; set; }
}
Job handler
The job handler is an implementation of IJobHandler<TJob>, IJobHandler<TJob, TResponse>, IAsyncJobHandler<TJob> or IAsyncJobHandler<TJob, TResponse>. Job handlers are automaticly added to the DI container, therefore you can use dependency injection inside the job handlers. The default job handler configuration can be overwritten with AbstractJobHandlerAttribute implementations, see attributes for more information.
public class SimpleJobHandler : IAsyncJobHandler<SimpleJob>
{
public async Task HandleJob(SimpleJob job, CancellationToken cancellationToken)
{
//TODO: make the handling idempotent.
await Usecase.ExecuteAsync(cancellationToken);
}
}
A handled job has three outcomes:
- The job has been handled without exceptions: this will automaticly result in a
JobCompletedCommandbeeing send to the broker. TheTResponseis automaticly serialized and added to theJobCompletedCommand. - An exception has been thrown while handling the job and the exception implements
AbstractJobException: this wil automaticly result in aThrowErrorCommandbeeing send to the broker; - Any other exception will automaticly result in a
FailCommandbeeing send to the broker;
The JobCompletedCommand accepts variables which are added to process instance. For this use case the job handler can be use with a second generic parameter IJobHandler<TJob, TResponse>. The response is automaticly serialized.
public class SimpleJobHandler : IAsyncJobHandler<SimpleJob, SimpleResponse>
{
public async Task<SimpleResponse> HandleJob(SimpleJob job, CancellationToken cancellationToken)
{
//TODO: make the handling idempotent.
var result = await Usecase.ExecuteAsync(cancellationToken);
return new SimpleResponse(result);
}
}
Extensions
IPublishMessageCommandStep3,ICreateProcessInstanceCommandStep3andISetVariablesCommandStep1are extended with theState(object state)method which uses the registeredIZeebeVariablesSerializerservice to automaticly serialize state and pass the result to theVariables(string variables)method.
Conventions
This project uses the following conventions:
- By default the simple name of the
AbstractJobimplementation is used to match theTypewhich is specified in the BPMN model. This can be overriden by adding theJobTypeAttributeto theAbstractJobimplementation, see attributes for more information. - By default the assembly name which contains the job handler is used as the
Worker name. This can be overriden by adding theWorkerNameAttributeto theAbstractJobimplementation, see attributes for more information. - By default the job handlers are added to de DI container with a
Transientservice lifetime. This can be overriden by adding theServiceLifetimeAttributeto the job handler, see attributes for more information. - By default the
ZeebeVariablesSerializeris registered as the implementation forIZeebeVariablesSerializerwhich usesSystem.Text.Json.JsonSerializer. You can override this registration by registering your service after theBootstrapZeebemethod or you can registerSystem.Text.Json.JsonSerializerOptionsto 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 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Hosting (>= 6.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- zb-client (>= 1.2.1)
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 | 15,471 | 9/21/2022 |
| 0.1.5 | 3,995 | 7/29/2022 |
| 0.1.4 | 539 | 7/29/2022 |
| 0.1.3 | 16,809 | 2/12/2022 |
| 0.1.2 | 679 | 2/2/2022 |
| 0.1.1 | 1,638 | 12/1/2021 |
| 0.1.0 | 504 | 11/17/2021 |
| 0.0.8 | 7,736 | 10/24/2021 |
| 0.0.7 | 457 | 10/21/2021 |
| 0.0.6 | 511 | 10/12/2021 |
| 0.0.5 | 464 | 10/12/2021 |
| 0.0.4 | 454 | 9/29/2021 |
| 0.0.3 | 463 | 9/6/2021 |
| 0.0.2 | 485 | 9/3/2021 |
| 0.0.1 | 473 | 9/2/2021 |
| 0.0.1-preview010 | 349 | 8/25/2021 |
| 0.0.1-preview007 | 345 | 8/25/2021 |
| 0.0.1-preview006 | 347 | 8/25/2021 |
| 0.0.1-preview005 | 356 | 8/23/2021 |