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.
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.