Stateless worker grains
As we know, grains in Orleans will have only one activation at a given time to process messages received. This is the fundamental design principle behind Orleans grains. Consider a situation where we need to transform the data received from the client, we need to calculate a discount based on a price for our Distel application, or we need to route messages to another grain. In all these scenarios, we just need to process or route the data received. Those operations are not tied to a specific entity. To support such scenarios, Orleans has stateless worker grains.
To define a stateless worker grain, we just need to add the [StatelessWorker]
attribute to the grain class. Now, let's build a simple discount computation grain for Distel by following these steps:
- Add the grain interface
IDiscountCalculator
to theDistel.Grains.Interfaces
project as shown in the following code snippet:public interface IDiscountCalculator : IGrainWithIntegerCompoundKey...