다음을 통해 공유


Registry Pattern Using Microsoft Orleans

Introduction

Microsoft Orleans is a virtual actor model framework build on top of Microsoft .net , As a virtual Actor framework the core building blocks for any system build with it is the Actor Objects(Grains) and by definition Grains are domain objects example {User , Student , Teacher , ...} any domain object should represent a real object in real life. Microsoft Orleans framework take care of Grains State Storage and retrieval using the storage provider pattern.

Problem Statement

Having Grains as Domain Objects was never sufficient as usually a query will be needed to get some specific objects for example I want to get all the active users in the system. An entry point object is needed in order to get this set of objects.

Solution

Registry object is a special type of grains who carry references to another objects , For example We can have a registry grain UsersRegisteryGrain with string primary key "Active" to hold references (Ids) of the Active Users Grain. When a user got activated it is Id should get registered in the UserRegisteryGrain("Active") and when he get deactivated his Id shell be removed from it. In fact the state of a Registry Grain should only be a HashSet of Id's of the objects that it shall store reference too.

Registry Storage Provider

After doing some researches we propose Azure table storage as storage provider

  • For every registry object a separate Azure table should be created (UserRegisteryGrain --> UserRegisteryTable)
  • Registry Primary key should be used as a Partition Key In the Grain Table
  • Each Entry In the Registry State (Hashset) should be a used as Row Key in the Azure Table ,more information related to the context can be stored but in general keep it simple

Complex Queries

Registry are the building blocks for any Query , Queries must be predefined as no Adhoc Queries could be done In order to be able to retrieve any kind of data you should create a registry for it is objects first.

General Guidelines For Building Queries And Registries

  • Start by writing down the queries you need
  • Break down any complex query that contains (And , Or , Not) in to sample query
  • Sample Query should represent only one class of the objects classification (Active Users , Male Users , ...)
  • You can have a parametrized Query with single Parameter like UserJoinedAfter(Date)
  • Identify When objects should be registered and unregistered from the registry (when I will consider user Active ? , when should I remove him from the registry ?)
  • Use the Union , Intersection and any other set operator to answer your complex query