Hi Markus,
Data Access - Create one dll for data access layer do database. Both Web and Worker role will use it to CRUD actions same way. Just reference it in both roles and use it.
Your approach:
- Worker Role puts data from database in some tables in TableStorage.
- Web Role access tables in TableStorage.
- If user changes values Web Role sends a message to Worker Role to update data.
- Worker Role updates data in database and sends a notification message back.
My approach(maybe simplier then I describe before):
- Web role will use UI to insert data into SQL Azure table(s) with information that it it is not processed(bit column named Processed set to false)
- (Optional 1) Web role insert message into Queue(named UnprocessedQueue) to notify worker role, there is some work to do
- (Optional 1) Worker role peek the
UnprocessedQueue for new messages
- (Optional
1) If there are some messages, take them(up to 32 messages at once) and process them
- (Optional
1) Each message got some information which entity(for one table it is id, for more it
is entity type and id) worker role have to process
- (Optional
2) Worker role will query for entities in SQL Azure table(s) for entities with bit column named Processed set to false in some time interval
- Both of optional approaches will result in some data set which you have to process in some foreach
loop
- In foreach you have to process the data and save them in the same or different table(you have to
determine what will be better) and after it mark this entity as processed with bit column Processed set to true and by setting new bit column named NewOrUpdated set to true.(each time entity is processed you have to set NewOrUpdated to true and you'll use
this bit value later in web role)
- When somebody login to see if the data update is done....you'll select entity with bit value Processed
set to true and NewOrUpdated set to true
- Usually you'll show the list of processed items...when user open one item to view the result you
can mark it as NewOrUpdated to false or you can wait after user mark it as viewed. This mechanism will help you to simplify the notification between job done worker role and web role with UI.
This is my point of view at this kind of app, but it depends on real data and usage. Its only some kind of practise I'll use, but it nos universal solution.
Hope this one helps you to understand to my ideas :-)
Microsoft Platform Developer Cloudikka blog