Fabric Service Actors - save state in database

I am working on a typical Fabric project where I need to maintain a shopping list. For this, I have an actor ShoppingList, which is identified by a specific identifier. It stores the contents of the current list in its state using the StateManager. Everything is working fine.

However, in parallel, I would like to save the contents of the shopping list in the sql database. In particular:

  • save all add / remove query element for future analysis (ML)
  • in the first initialization element, loads the contents of the boot list from db (for example, after the cluster has been recreated)

What is the best approach to achieve this? Create a custom StateProvider (how? Can't find examples)? Or maybe you have another service / actor to handle all db operations (possibly using queues and reminders)?

All of the examples seem to rely entirely on stateManager by default, without preserving data constancy for external storage, so I'm not sure which is best.

+4
source share
1 answer

The best way would be to have a separate object responsible for storing data in the database. And the actor will simply send an event (without implying SF events) with some data about the operation performed, and another object will catch it and do the rest of the work.

, , , :

  • , . , DB .
  • .

, . , , .

, , , . .

, - . , +, , , , , -. , , - .

: . , , , IReliableStateManagerReplica StatefullService.

+5

Source: https://habr.com/ru/post/1648016/


All Articles