Real Time Tracking Plugin
The Real Time Tracking Plugin enhances the user experience by providing instant updates on process instances without the need for page reloads. This is made possible by leveraging web sockets, ensuring seamless communication with clients.
Configuration and integration
Backend
First, you need to integrate the plugin into the backend of your ASP.NET application. Usually, this code should be placed in
the Program.cs
file of your ASP.NET application.
Use the AddRealTimeTracking
to add the necessary services for tracking to work.
builder.Services.AddRealTimeTracking();
Add a new endpoint using the MapRealTimeTracking
method.
app.UseEndpoints(endpoints =>
{
endpoints.MapRealTimeTracking();
});
When adding an endpoint in the MapRealTimeTracking
method, you can specify the route for the plugin to operate. By default, it's
"/workflowHub".
Next, create an instance of RealTimeTrackingPlugin
and pass it when initializing WorkflowRuntime
. There are two constructors to choose
from, depending on your application's structure.
If your WorkflowRuntime is initialized outside the .NET dependency injection infrastructure and not in the service, use this constructor:
// public RealTimeTrackingPlugin(IServiceProvider serviceProvider)
var trackingPlugin = new RealTimeTrackingPlugin(serviceProvider);
If WorkflowRuntime
is created as a service, you can use the following constructor. This allows you to utilize the NotifierService
that
was injected, for instance, into the constructor of the service where your WorkflowRuntime is initialized:
//public RealTimeTrackingPlugin(NotifierService notifierService)
var trackingPlugin = new RealTimeTrackingPlugin(notifierService);
Next, register the plugin in the WorkflowRuntime
instance:
WorkflowRuntime runtime = ...
runtime
...
.WithPlugin(pluginTracker)
.AsSingleServer() //.AsMultiServer()
.Start();
The plugin determines if WorkflowRuntime
operates in single-server or multi-server mode, enabling the corresponding type of tracking. For
tracking in multi-server mode, the database is polled for changes in the monitored process, with a default polling interval of 2 seconds.
You can change this interval when initializing the plugin:
var trackingPlugin = new RealTimeTrackingPlugin(serviceProvider, new RealTimeTrackingPluginSettings()
{
MultiServerModeProcessPollInterval = TimeSpan.FromMilliseconds(500)
});
Frontend
On the frontend, you will only need to make sure that the url to which the SignalR hub connects is specified.
wfdesigner = new WorkflowDesigner({
...
realTimeTrackingUrl: '/workflowHub',
...
})
Using with already registered SignalR
Please note that if SignalR is already being used in your project, it is better to manually register all necessary services, rather than
using the methods AddRealTimeTracking
and MapRealTimeTracking
. Therefore, their very simple code is provided below:
public static IServiceCollection AddRealTimeTracking(this IServiceCollection services)
{
services.AddSignalR();
services.AddSingleton<NotifierService>();
return services;
}
public static HubEndpointConventionBuilder MapRealTimeTracking(this IEndpointRouteBuilder endpoints, string pattern = "/workflowHub")
{
return endpoints.MapHub<WorkflowEngineHub>(pattern);
}
Usage
With the integrated plugin, any changes in the process execution will be immediately reflected in your designer. To illustrate, please refer to the example below.