-
Notifications
You must be signed in to change notification settings - Fork 1.2k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to subscribe to workflow and activity events to get changed status using Elsa 3.0? #5125
Comments
To subscribe to workflow and activity events in Elsa 3.0, you can use the event handling features provided by Elsa to listen for specific events and react accordingly. Elsa 3.0 has a robust event system that allows you to subscribe to various workflow-related events, such as when an activity is executed, when a workflow is started, or when a workflow is halted. Here is an example code snippet that demonstrates how to subscribe to workflow and activity events: public class MyWorkflowEventHandler
{
private readonly IEventPublisher _eventPublisher;
public MyWorkflowEventHandler(IEventPublisher eventPublisher)
{
_eventPublisher = eventPublisher;
}
public void Subscribe()
{
_eventPublisher.Subscribe<WorkflowStarted>(OnWorkflowStarted);
_eventPublisher.Subscribe<WorkflowCompleted>(OnWorkflowCompleted);
_eventPublisher.Subscribe<ActivityExecuted>(OnActivityExecuted);
_eventPublisher.Subscribe<ActivityFaulted>(OnActivityFaulted);
}
private void OnWorkflowStarted(WorkflowStarted context)
{
// Handle the workflow started event
Console.WriteLine($"Workflow {context.WorkflowInstanceId} started.");
}
private void OnWorkflowCompleted(WorkflowCompleted context)
{
// Handle the workflow completed event
Console.WriteLine($"Workflow {context.WorkflowInstanceId} completed.");
}
private void OnActivityExecuted(ActivityExecuted context)
{
// Handle the activity executed event
Console.WriteLine($"Activity {context.ActivityId} executed in workflow {context.WorkflowInstanceId}.");
}
private void OnActivityFaulted(ActivityFaulted context)
{
// Handle the activity faulted event
Console.WriteLine($"Activity {context.ActivityId} faulted in workflow {context.WorkflowInstanceId}.");
}
} In this example, Please note that the exact implementation details may vary depending on the version of Elsa you are using and the specific requirements of your application. For the most accurate and up-to-date information, you should refer to the official Elsa documentation and examples. |
bu there is no "Subscribe" method in "IEventPublisher". @noxe @petedavis |
@coolshun
then register all your handlers in startup by single call
Note Example above works on Elsa Server 3.0.6 The list of available events
|
@msavencov I have another question, can you help me? #5131 How to create a workflow instance without immediately executing it and execut it later? |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
How to subscribe to workflow and activity events to get changed status using Elsa 3.0? I want to get the status in business system.I want to get a example code.
The text was updated successfully, but these errors were encountered: