I am designing a 2 WCF services that all my clients will connect to. One of these services will be a notifications service.
I would like each client to connect to the service, subscribe to it and then receive notifications, using a duplex Callback interface (the service will fire the 'Notify' operation in the clients).
This is my Design Idea:
My question is: When each client connects to my service, I will validate it against the 'Users' table in my database (I will be using a UserNamePasswordValidator and implement the 'Validate' function).
Requirement: Each user needs to receive different notifications, based on rules defined in the database, but they all use the same contract.
For example:
John Smith's rules in the DB might be : Notify me on all new products that have a price of over 100 dollars.
Jane Doe's rules in the DB might be : Notify me on all new products that their names begin with 'JA'.
Jim Jabra's rules in the DB might be : Notify me on all new products that are of type 'Food'.
My service will have a worker thread that detects a change in the database (a new product was inserted to the database).
It should then loop over all the clients connected - and for each client send him a notification of the new product, only if it matches the client's notification requests.
Again - all clients receive the same type of update (new products), but each client should receive different products according to the rule in the database.
One approach I thought to implement this would be to use a Singleton service, that holds a list of :
- Client Enpoint
- User Object (from database)
This way - each time the worker thread detects a new product, it loops over this list and send notifications to whome ever needs it. The problem with this approach is that in order to have one global list of clients - I need to have the service as a Singlton, right ?
The second approach would be ... well ... I don't have another idea of how I can access a list of clients connected to the service from a worker thread ...
I guess the main problem I have is that each client might want different kinds of product notified to him. Meaning - the pub\sub method is not so good here, because my scenario requires the service to know about the clients.
Any suggestions on how I can solve this headaches ?