Stateless service lifecycle

Let's take a close look at the lifecycle of a stateless Service Fabric Reliable Service. The lifetime of a stateless Microservice starts as soon as you register a new instance of the service with the Service Fabric runtime. The following are the major lifetime events of a stateless Microservice:

  • CreateServiceInstanceListeners(): This method is used to setup communication listeners for client requests. Although, Service Fabric provides a default communication listener based on RPC proxy, you can override this method to supply our communication stack of choice. The endpoints returned by the communication listeners are stored as a JSON string of listener name and endpoint string pairs like {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}
  • OnOpenAsync(IStatelessServicePartition, CancellationToken): This method is called when the stateless service instance is about to be used. This method should generally be used in conjunction with its counterpart method OnCloseAsync to initialize resources that are used by the service such as open connections to external systems, start background processes and setup connections with databases, and so on.
  • RunAsync(CancellationToken): This method is a general-purpose entry point for the business logic of your Microservice. This method is invoked when a service instance is ready to begin execution. A cancellation token is provided as input to the method to signal your Microservice that processing should stop. You should only implement this method if your service is continuously processing some data, for example consuming messages from a queue and processing them.
  • OnCloseAsync(CancellationToken): In multiple scenarios, your Microservice may be requested to shut down, for example when the code of your service is being upgraded, when the service instance is being moved due to load balancing, or when a transient fault is detected. In such cases, the Service Fabric runtime will trigger the OnCloseAsync method to signal your Microservice to start performing the clean-up operations. This method should be used in conjunction with the OnOpenAsync method to clean up resources after they have been used by the service.
  • OnAbort(): OnAbort is called when the stateless service instance is being forcefully shut down. This is generally called when a permanent fault is detected on the node, or when Service Fabric cannot reliably manage the service instance's lifecycle due to internal failures:
Stateless service lifetime
..................Content has been hidden....................

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