Skip to content

camunda-community-hub/zeebe-client-csharp

Repository files navigation

Build Status Total alerts

Zeebe C# client

The Zeebe C# client is a C# wrapper implementation around the GRPC (https://github.com/grpc/grpc) generated Zeebe client. It makes it possible to communicate with Zeebe Broker via the GRPC protocol, see 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 zeebe release (0.14.0)

How to use

The Zeebe C# client is available via nuget (https://www.nuget.org/packages/zb-client/).

How to build

Simply run msbuild Zeebe.sln or dotnet build Zeebe.sln

Current supported Features

  • Request topology
  • JobWorker
  • Complete Job
  • Fail Job
  • Publish Message
  • Deploy an resource
  • Create a workflow instance
  • Update an element instance payload
  • Update retries of an job
  • Resolve an existing incident
  • Cancel an existing workflow instance
  • List all workflows
  • Request a workflow resource

Examples

To create a client use this:

  var zeebeClient = ZeebeClient.NewZeebeClient("localhost:26500");

Request topology

  ITopology top = await zeebeClient.TopologyRequest().Send(); 

Create an job worker

  zeebeClient.NewWorker()
      .JobType("bar")
      .Handler((client, job) =>
      {
        // business logic
      })
      .Limit(5)
      .Name("zb-worker")
      .PollInterval(TimeSpan.FromSeconds(5))
      .Timeout(10_000L)
      .Open();

Complete an job

client.NewCompleteJobCommand(JobKey).Payload("{\"foo\":23}").Send();

Fail an job

client.NewFailCommand(job.Key).Retries(job.Retries - 1).ErrorMessage("This job failed.").Send();

Deploy a resource

var deployResponse = await client.NewDeployCommand().AddResourceFile(DemoProcessPath).Send();

Create a workflow instance

var workflowKey = deployResponse.Workflows[0].WorkflowKey;
var workflowInstanceResponse = await client
    .NewCreateWorkflowInstanceCommand()
    .WorkflowKey(workflowKey)
    .Payload("{\"foo\":\"123\"}")
    .Send();

Update payload of an element instance

await client.NewUpdatePayloadCommand(workflowInstanceResponse.WorkflowInstanceKey)
    .Payload("{\"a\":\"newPayload\"}")
    .Send();

Update retries of an job

await client.NewUpdateRetriesCommand(45).Retries(2).Send();

Resolve an existing incident

await client.NewResolveIncidentCommand(17).Send();

Cancel an existing workflow instance

await client.NewCancelInstanceCommand(workflowInstanceResponse.WorkflowInstanceKey).Send();

List all workflows

var workflowListResponse = await client.NewListWorkflowRequest().Send();

Request workflow resource

var workflowResourceResponse = await client.NewWorkflowResourceRequest().BpmnProcessId("ship-parcel").LatestVersion().Send();