The ScaleHub is a lib designed for managing scales in distributed applications. It provides tools for monitoring the number of service replicas and synchronizing data across multiple instances or servers. The project includes Service Broker for real-time data updates, background services, and external synchronization components.
-
External Synchronization: Implement external real-time synchronization to keep data consistent across instances.
-
Event Architecture Oriented: Instantly receive notifications when changes occur, allowing your application to react promptly, with
OnSubscribingandOnUnsubscribingevents.
To use the ScaleHub project, follow these steps:
-
Configure ScaleHub: Use the
AddScaleHubto inject theIScaleHub. -
Specify integration: Configure the project to connect to your external service, like SQL Server database. You can use
UseSqlServermethod for this purpose. -
Monitoring: Use the
IScaleHubto obtain infomations about your instance and the number of replicas.public class ScaleContext { public int Replicas { get; set; } public int Actual { get; set; } }
-
Configure Events: [optional] Make use of the
ConfigureSubsmethod to monitor and deal with replicas number change.-
OnSubscribing: Configure events to trigger when a new replica is added.
-
OnUnsubscribing: Configure events to trigger when a old replica is removed.
-
services.AddScaleHub(opt =>
{
opt.UseSqlServer("your_connection_string");
opt.ConfigureSubs(e =>
{
e.OnSubscribing += LogNewReplica;
e.OnUnsubscribing += LogOldReplica;
});
});
// 5. Start and monitor your distributed application using the ScaleHub system.