예제 #1
0
        static void Main(string[] args)
        {
            //TODO: Get config for the sidecar from the WebAPI it is bridging to.  http://localhost:5000/api/camundaconfig
            var           topicConfigs = FetchCamundaConfigs("http://localhost:5000");
            CamundaClient camunda      = CamundaClient.Create("http://localhost:8080/engine-rest");

            while (true)
            {
                var topicList = new FetchExternalTasks()
                {
                    AsyncResponseTimeout = 10000,
                    MaxTasks             = 50,
                    Topics   = new List <FetchExternalTaskTopic>(),
                    WorkerId = "myworkerId"
                };
                foreach (var config in topicConfigs)
                {
                    topicList.Topics.Add(new FetchExternalTaskTopic(config.Key, 10));
                }

                var allTasks = camunda.ExternalTasks.FetchAndLock(topicList).Result;
                Console.WriteLine($"Number of Tasks:{allTasks.Count}");
                foreach (var task in allTasks)
                {
                    var realtask = camunda.ExternalTasks[task.Id].Get().Result;

                    var response = CallTheSyncMethod(task.Variables["AsyncPostRequest"], topicConfigs[task.TopicName]);

                    CompleteTask(camunda, task, response);
                }

                Thread.Sleep(5000);
            }
        }
예제 #2
0
        public async Task CompleteTest()
        {
            var client          = CamundaClient.Create("http://localhost:8080/engine-rest");
            var processInstance = await client.ProcessDefinitions.ByKey("ExternalTaskTest")
                                  .StartProcessInstance(new StartProcessInstance());

            Assert.NotNull(processInstance);

            var externalTasks = await client.ExternalTasks.FetchAndLock(new FetchExternalTasks()
            {
                WorkerId = "DOT-NET-TEST",
                MaxTasks = 1,
                Topics   = new List <FetchExternalTaskTopic>()
                {
                    new FetchExternalTaskTopic("external-task", 10000L)
                }
            });

            Assert.NotNull(externalTasks);
            Assert.True(externalTasks.Count > 0);

            externalTasks.ForEach(action: async externalTask => {
                await client.ExternalTasks.Complete(externalTask.Id, new CompleteExternalTask()
                {
                    WorkerId = "DOT-NET-TEST"
                });
            });
        }
예제 #3
0
        public async Task <IActionResult> UserRegistration(RegistrationModel request)
        {
            _logger.LogInformation("Registering new user...");
            _logger.LogInformation($"name: {request.Name}");

            try
            {
                // Starting camunda client
                CamundaClient camunda = CamundaClient.Create("http://localhost:8080/engine-rest");

                // New process defintion
                StartProcessInstance newProcessInstance = new StartProcessInstance();
                newProcessInstance.SetVariable("name", VariableValue.FromObject(request.Name));
                newProcessInstance.SetVariable("password", VariableValue.FromObject(request.Password));

                // Sending process to camunda
                await camunda.ProcessDefinitions.ByKey("user_registration").StartProcessInstance(newProcessInstance);

                return(StatusCode(StatusCodes.Status200OK));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error calling user registration for user {request.Name}");
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public ExternalTaskWorker(
            CamundaClient camundaClient,
            ExternalTaskWorkerInfo externalTaskWorkerInfo,
            WorkerSettings workerSettings)
        {
            _camundaClient          = camundaClient;
            _externalTaskWorkerInfo = externalTaskWorkerInfo;

            _pollingInterval = workerSettings.ExternalTaskSettings.PollingInterval;
            var lockDuration = workerSettings.ExternalTaskSettings.LockDuration;

            _maxDegreeOfParallelism = workerSettings.ExternalTaskSettings.MaxDegreeOfParallelism;
            var maxTasksToFetchAtOnce = workerSettings.ExternalTaskSettings.MaxTasksToFetchAtOnce;

            var topic = new FetchExternalTaskTopic(_externalTaskWorkerInfo.TopicName, lockDuration)
            {
                Variables = _externalTaskWorkerInfo.VariablesToFetch
            };

            _fetching = new FetchExternalTasks()
            {
                WorkerId    = _workerId,
                MaxTasks    = maxTasksToFetchAtOnce,
                UsePriority = true,
                Topics      = new List <FetchExternalTaskTopic>()
                {
                    topic
                }
            };
        }
예제 #5
0
 private CamundaClient CreateCamundaClient()
 {
     if (camundaClient == null)
     {
         camundaClient = CamundaClient.Create(txtCamundaRestUrl.Text.Trim());
     }
     return(camundaClient);
 }
예제 #6
0
        private static void CompleteTask(CamundaClient camunda, LockedExternalTask task, string response)
        {
            var completion = new CompleteExternalTask();

            completion.WorkerId = task.WorkerId;
            completion.SetVariable("AsyncPostResponse", response);
            camunda.ExternalTasks[task.Id].Complete(completion);
            Console.WriteLine($"Finsihed Processing {task.Id} for {task.WorkerId}");
        }
예제 #7
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation($"{WORKER_ID} running at: {DateTimeOffset.Now}");

                // Starting camunda client
                CamundaClient camunda = CamundaClient.Create("http://localhost:8080/engine-rest");

                // Fetching available tasks for that topic
                var fetchExternalTasks = new FetchExternalTasks()
                {
                    MaxTasks = 10,
                    WorkerId = WORKER_ID,
                    Topics   = new List <FetchExternalTaskTopic>()
                    {
                        new FetchExternalTaskTopic("persist_user", 2000)
                    }
                };

                List <LockedExternalTask> lockedExternalTasks = await camunda.ExternalTasks.FetchAndLock(fetchExternalTasks);

                // Processing the tasks
                foreach (LockedExternalTask lockedExternalTask in lockedExternalTasks)
                {
                    // Loading all variables from this task
                    Dictionary <string, VariableValue> taskVariables = lockedExternalTask.Variables;

                    var name     = taskVariables["name"];
                    var password = taskVariables["password"];
                    var userId   = new Random().Next(1, 100);

                    // Process the task as you wish
                    _logger.LogInformation($"Persisting on DB. New user: {name}, password: {password}. Generated ID: {userId}");

                    // Setting output variables
                    Dictionary <string, VariableValue> outputVariables = new Dictionary <string, VariableValue>
                    {
                        { "user_id", VariableValue.FromObject(userId) }
                    };

                    // Completes task
                    var completeExternalTask = new CompleteExternalTask()
                    {
                        Variables = outputVariables,
                        WorkerId  = WORKER_ID,
                    };

                    await camunda.ExternalTasks[lockedExternalTask.Id].Complete(completeExternalTask);
                }

                await Task.Delay(_serviceConfiguration.Interval, stoppingToken);
            }
        }
예제 #8
0
        public static CamundaClient GetCamundaClient(CamundaClient client)
        {
            var cl = client ?? Global.CamundaClient;

            if (cl == null)
            {
                throw new Exception("Can't find CamundaClient...");
            }

            return(cl);
        }
        public void Post([FromBody] string value)
        {
            var           businessKey = Guid.NewGuid();
            CamundaClient camunda     = CamundaClient.Create("http://localhost:8080/engine-rest");
            var           instance    = new Camunda.Api.Client.ProcessDefinition.StartProcessInstance();

            instance.BusinessKey = businessKey.ToString();
            instance.SetVariable("ExternalTaskName", "DoAsyncWork");
            instance.SetVariable("ExternalCallbackTaskName", "AsyncWork_Completed");
            instance.SetVariable("AsyncPostRequest", value);
            camunda.ProcessDefinitions.ByKey("AsyncWebAPI").StartProcessInstance(instance);
        }
예제 #10
0
        public async Task GetVersion()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Get, "http://localhost:8080/engine-rest/version")
            .Respond(HttpStatusCode.OK, "application/json", "{\"version\": \"7.14.0\"}");


            var client  = CamundaClient.Create("http://localhost:8080/engine-rest", mockHttp);
            var version = await client.Version.Get();

            Assert.Equal("7.14.0", version.Version);
        }
예제 #11
0
        public async Task GetList()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Post, "http://localhost:8080/engine-rest/process-instance")
            .Respond(HttpStatusCode.OK, "application/json", "[]");


            var client  = CamundaClient.Create("http://localhost:8080/engine-rest", mockHttp);
            var process = await client.ProcessInstances.Query().List();

            Assert.NotNull(process);
        }
        public ExternalTaskClient Build()
        {
            var httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(baseUrl);
            if (username != null && password != null)
            {
                var encodedCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(username + ":" + password));
                httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + encodedCredentials);
            }
            CamundaClient camundaClient = CamundaClient.Create(httpClient);

            return(new ExternalTaskClient(camundaClient, workerId));
        }
예제 #13
0
        protected override void ProcessRecord()
        {
            var client = new CamundaClient(opts => {
                opts.WithCamundaRestApiUrl(RestApiUrl);
                opts.WithProxy(Proxy, ProxyCredential?.GetNetworkCredential());
            });

            if (Global)
            {
                PsClient.Global.CamundaClient = client;
            }
            else
            {
                WriteObject(client);
            }
        }
예제 #14
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation($"{WORKER_ID} running at: {DateTimeOffset.Now}");

                // Starting camunda client
                CamundaClient camunda = CamundaClient.Create("http://localhost:8080/engine-rest");

                // Fetching available tasks for that topic
                var fetchExternalTasks = new FetchExternalTasks()
                {
                    MaxTasks = 10,
                    WorkerId = WORKER_ID,
                    Topics   = new List <FetchExternalTaskTopic>()
                    {
                        new FetchExternalTaskTopic("send_email", 2000)
                    }
                };

                List <LockedExternalTask> lockedExternalTasks = await camunda.ExternalTasks.FetchAndLock(fetchExternalTasks);

                // Processing the tasks
                foreach (LockedExternalTask lockedExternalTask in lockedExternalTasks)
                {
                    // Loading all variables from this task
                    Dictionary <string, VariableValue> taskVariables = lockedExternalTask.Variables;

                    var userId = taskVariables["user_id"];

                    // Process the task as you wish
                    _logger.LogInformation($"Sending email to user: {userId}");

                    // Completes task
                    var completeExternalTask = new CompleteExternalTask()
                    {
                        WorkerId = WORKER_ID
                    };

                    await camunda.ExternalTasks[lockedExternalTask.Id].Complete(completeExternalTask);
                }

                await Task.Delay(_serviceConfiguration.Interval, stoppingToken);
            }
        }
예제 #15
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddArchManager <MyArch>();

            services.AddControllers();
            services.AddRazorPages().AddRazorRuntimeCompilation();
            services.AddSingleton(ctx =>
            {
                HttpClient httpClient  = new HttpClient();
                httpClient.BaseAddress = new Uri("http://localhost:8080/engine-rest");
                httpClient.DefaultRequestHeaders.Add("Authorization", "Basic ZGVtbzpkZW1v");
                CamundaClient camunda = CamundaClient.Create(httpClient);
                return(camunda);
            });

            services.AddHttpClient <TasksService>(ctx => ctx.BaseAddress = new Uri("http://127.0.0.1:8080"));
            services.AddCors();
            services.AddOpenApiDocument();
        }
예제 #16
0
        public CamundaClient Client()
        {
            if (_camunda != null)
            {
                return(_camunda);
            }

            var proxy = new WebProxy
            {
                BypassProxyOnLocal = true
            };

            if (_proxySettings.IsEnabled)
            {
                proxy.Address = new Uri(_proxySettings.Url);
                proxy.UseDefaultCredentials = true;
            }

            var httpClientHandler = new HttpClientHandler
            {
                Proxy = proxy
            };

            var httpClient = new HttpClient(httpClientHandler)
            {
                BaseAddress = new Uri(_camundaSettings.Url)
            };

            if (!string.IsNullOrEmpty(_camundaSettings.Username))
            {
                var byteArray = Encoding.ASCII.GetBytes($"{_camundaSettings.Username}:{_camundaSettings.Password}");
                httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
            }

            _camunda = CamundaClient.Create(httpClient);
            return(_camunda);
        }
 public TasksController(CamundaClient camunda, TasksService tasksService)
 {
     this.camunda      = camunda;
     this.tasksService = tasksService;
 }
 public ProcessEngineTestHelper()
 {
     CamundaClient = CamundaClient.Create("http://localhost:8090/engine-rest");
 }
예제 #19
0
 public ExternalTaskClient(CamundaClient camundaClient, string workerId)
 {
     this.camundaClient = camundaClient;
     this.workerId      = workerId;
 }
예제 #20
0
 public BpmnService(string camundaRestApiUri)
 {
     this.camunda = CamundaClient.Create(camundaRestApiUri);
 }