Stateful service lifecycle

Let's explore the lifecycle of a stateful service. The lifetime of a stateful Microservice replica starts as soon as you register a new instance of the service with the Service Fabric runtime. Most of the lifetime methods are same as that of stateless Microservice. Let's look at those that are different:

  • RunAsync (CancellationToken): In a stateful service, the platform performs additional work on your behalf before it executes RunAsync (). This work can include ensuring that the Reliable State Manager and Reliable Collections are ready to use. This method executes only in the active primary replica.
  • OnChangeRoleAsync (ReplicaRole, CancellationToken): OnChangeRoleAsync is called when the stateful service replica is changing role, for example to primary or secondary. Primary replicas are given write status (are allowed to create and write to Reliable Collections). Secondary replicas are given read status (can only read from existing Reliable Collections). Most work in a stateful service is performed at the primary replica. Secondary replicas can perform read-only validation, report generation, data mining, or other read-only jobs. The stateful service lifetime can be seen in the following image:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.61.30