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 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" }); }); }
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); } }
private CamundaClient CreateCamundaClient() { if (camundaClient == null) { camundaClient = CamundaClient.Create(txtCamundaRestUrl.Text.Trim()); } return(camundaClient); }
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); } }
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); }
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); }
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)); }
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); } }
// 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(); }
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 ProcessEngineTestHelper() { CamundaClient = CamundaClient.Create("http://localhost:8090/engine-rest"); }
public BpmnService(string camundaRestApiUri) { this.camunda = CamundaClient.Create(camundaRestApiUri); }