'How do I send a signal to ELSA workflow using C#, SendSignal and SignalReceived activities?
I'd like to send a signal from my C# API code, probably using the SendSignal activity to a workflow that will receive that signal using the SignalReceived activity.
Solution 1:[1]
To send a signal to a workflow from your own code, such as a controller or any other class, you can use the ISignaler
service.
Here's an example:
[ApiController]
[Route("myapi")]
public class MyApi: Controller
{
private readonly ISignaler _signaler;
public MyApiController(ISignaler signaler)
{
_signaler = signaler;
}
[HttpPost("send-signal")]
public async Task<IActionResult> SendSignal(CancellationToken cancellationToken)
{
var startedWorkflows = await _signaler.TriggerSignalAsync("MySignal", cancellationToken: cancellationToken);
return Ok(startedWorkflows);
}
}
A complete sample project can be found here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sipke Schoorstra |