Zeebe Client C#

Hello there, I am using Zeebe Client C# for Camunda, however I cannot connect my camunda platform, return this error:
Grpc.Core.RpcException: ‘Status(StatusCode=“Unavailable”, Detail=“failed to connect to all addresses”, DebugException=“Grpc.Core.Internal.CoreErrorDetailException: {“created”:”@1635497725.110000000",“description”:“Failed to pick subchannel”,“file”:"…\src\core\ext\filters\client_channel\client_channel.cc",“file_line”:3159,“referenced_errors”:[{“created”:"@1635497725.110000000",“description”:“failed to connect to all addresses”,“file”:"…\src\core\lib\transport\error_utils.cc",“file_line”:147,“grpc_status”:14}]}")’

I have saw the document and find I need to enable the Zeebe gateway. Am I right? If yes how to create TLS certificate for my Zeebe connection?

Hey @lawrence

thanks for trying Zeebe,
Please post your code you’re using, so we can help you here. It would also be interesting which version you’re using.

You can also check out this example zeebe-client-csharp/Program.cs at master · camunda-community-hub/zeebe-client-csharp · GitHub

Greets
Chris

Hello Zelldon

I am exactly using this example and using Client.Examples.
I just change ZeebeUrl pointing to my Camunda 8080 port.

Do you have any commend?

internal class Program
    {
        private static readonly string DemoProcessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "demo-process.bpmn");
        private static readonly string ZeebeUrl = "192.168.17.158:26500";
        private static readonly string ProcessInstanceVariables = "{\"a\":\"123\"}";
        private static readonly string JobType = "payment-service";
        private static readonly string WorkerName = Environment.MachineName;
        private static readonly long WorkCount = 100L;

        public static async Task Main(string[] args)
        {
            // create zeebe client
            var client = ZeebeClient.Builder()
                .UseLoggerFactory(new NLogLoggerFactory())
                .UseGatewayAddress(ZeebeUrl)
                .UsePlainText()
                .Build();

            var topology = await client.TopologyRequest()
                .Send();
            Console.WriteLine(topology);
            await client.NewPublishMessageCommand()
                .MessageName("csharp")
                .CorrelationKey("wow")
                .Variables("{\"realValue\":2}")
                .Send();

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

            // create process instance
            var processDefinitionKey = deployResponse.Processes[0].ProcessDefinitionKey;

            var processInstance = await client
                .NewCreateProcessInstanceCommand()
                .ProcessDefinitionKey(processDefinitionKey)
                .Variables(ProcessInstanceVariables)
                .Send();

            await client.NewSetVariablesCommand(processInstance.ProcessInstanceKey).Variables("{\"wow\":\"this\"}").Local().Send();

            for (var i = 0; i < WorkCount; i++)
            {
                await client
                    .NewCreateProcessInstanceCommand()
                    .ProcessDefinitionKey(processDefinitionKey)
                    .Variables(ProcessInstanceVariables)
                    .Send();
            }

            // open job worker
            using (var signal = new EventWaitHandle(false, EventResetMode.AutoReset))
            {
                client.NewWorker()
                      .JobType(JobType)
                      .Handler(HandleJob)
                      .MaxJobsActive(5)
                      .Name(WorkerName)
                      .AutoCompletion()
                      .PollInterval(TimeSpan.FromSeconds(1))
                      .Timeout(TimeSpan.FromSeconds(10))
                      .Open();

                // blocks main thread, so that worker can run
                signal.WaitOne();
            }
        }

        private static void HandleJob(IJobClient jobClient, IJob job)
        {
            // business logic
            var jobKey = job.Key;
            Console.WriteLine("Handling job: " + job);

            if (jobKey % 3 == 0)
            {
                jobClient.NewCompleteJobCommand(jobKey)
                    .Variables("{\"foo\":2}")
                    .Send()
                    .GetAwaiter()
                    .GetResult();
            }
            else if (jobKey % 2 == 0)
            {
                jobClient.NewFailCommand(jobKey)
                    .Retries(job.Retries - 1)
                    .ErrorMessage("Example fail")
                    .Send()
                    .GetAwaiter()
                    .GetResult();
            }
            else
            {
                // auto completion
            }
        }
    }

Hey @lawrence

may I ask what you mean with:

I just change ZeebeUrl pointing to my Camunda 8080 port.

I sounds for me like you’re using Camunda Bpm GitHub - camunda/camunda-bpm-platform: Flexible framework for workflow and decision automation with BPMN and DMN. Integration with Quarkus, Spring, Spring Boot, CDI. is this correct?

Greets
Chris

You need to use the Zeebe client with the Zeebe broker. You can’t use it with Camunda Platform. The engines are completely different.