Code Monkey home page Code Monkey logo

zeebe-client-csharp-bootstrap's Introduction

BUILD ANALYZE Compatible with: Camunda Platform 8

Bootstrap extension for the C# Zeebe client

This project is not maintained anymore and is deprecated. The reason for this decision is the resent fork of this project by zeebe-client-csharp-accelerator. Please switch to the zeebe-client-csharp-accelerator which is a copy of this project with some small functional changes in the interface. Because of this switching should be relatively easy.

Apologies for the inconvenience but for the long term it will be better for the community to have one code base which is actively supported.

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

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:

  1. ZeebeBootstrapOptions via configuration, action delegate or both.
  2. 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:

  1. The job has been handled without exceptions: this will automaticly result in a JobCompletedCommand beeing send to the broker. The TResponse is automaticly serialized and added to the JobCompletedCommand.
  2. An exception has been thrown while handling the job and the exception implements AbstractJobException: this wil automaticly result in a ThrowErrorCommand beeing send to the broker;
  3. Any other exception will automaticly result in a FailCommand beeing 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

  1. IPublishMessageCommandStep3, ICreateProcessInstanceCommandStep3 and ISetVariablesCommandStep1 are extended with the State(object state) method which uses the registered IZeebeVariablesSerializer service to automaticly serialize state and pass the result to the Variables(string variables) method.

Conventions

This project uses the following conventions:

  1. By default the simple name of the AbstractJob implementation is used to match the Type which is specified in the BPMN model. This can be overriden by adding the JobTypeAttribute to the AbstractJob implementation, see attributes for more information.
  2. By default the assembly name which contains the job handler is used as the Worker name. This can be overriden by adding the WorkerNameAttribute to the AbstractJob implementation, see attributes for more information.
  3. By default the job handlers are added to de DI container with a Transient service lifetime. This can be overriden by adding the ServiceLifetimeAttribute to the job handler, see attributes for more information.
  4. By default the ZeebeVariablesSerializer is registered as the implementation for IZeebeVariablesSerializer which uses System.Text.Json.JsonSerializer. You can override this registration by registering your service after the BootstrapZeebe method or you can register System.Text.Json.JsonSerializerOptions to configure the System.Text.Json.JsonSerializer.

How to build

Run dotnet build Zeebe.Client.Bootstrap.sln

How to test

Run dotnet test Zeebe.Client.Bootstrap.sln

zeebe-client-csharp-bootstrap's People

Contributors

arjangeertsema avatar arjentfe avatar celanthe avatar dependabot[bot] avatar eterne5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

zeebe-client-csharp-bootstrap's Issues

Feature to subscribe user task but not auto complete it

Is your feature request related to a problem? Please describe.

We want to subscribe user task information and store its information, so that we can complete it later. However, current implementation auto completes user task after executing the handler.

Describe the solution you'd like
User Task handler should be executed once but not auto completes it.

Connect to Camunda Saas Instances & SM instances with TLS

Is your feature request related to a problem? Please describe.

Unable to connect to a Camunda Saas Instance & SM Instance without plaintext

Describe the solution you'd like

Changes to the Zeebe client to connect to a Saas Instance & to connect to a SM instance with TLS security

Additional context

At the moment, we can only connect to a local instance of Camunda with plaintext security. The ZeebeClientAcceleratorOptions.ClientOptions only has GatewayAddress property. This could be extended to take values for Saas instances and enable connectivity with Saas Instances.

At the moment, any other address results in a Grpc.Core.RpcException
image

Integrations Test Failing After Upgrade To Docker Desktop v4.11.0

Describe the bug

After upgrading to Docker Desktop v4.11.0 the integrations test all failed.

To Reproduce

Steps to reproduce the behavior:

  1. Upgrade to v4.11.0
  2. Try any integration test

Expected behavior

All integrations test pass individually after allowing Docker to tear down the test instances.

Enviroment (please complete the following information):

  • OS: Windows 11
  • Docker Desktop: v.4.11.0

Additional context

I was able to resolve the problem locally by upgrading the Testcontainers nuget package reference in the Tests project.

Previous: PackageReference Include="DotNet.Testcontainers" Version="1.6.0"
New: PackageReference Include="Testcontainers" Version="2.1.0"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.