Reputation: 714
I'm looking to create an application that has events happening all the time. New data would be input into a staging table from various sources that will not be able to trigger another application or have access to business logic. These sources put the data into the table and once in the table it requires that the information be processed. An example would be multiple sources are able to order items and the sales go into a salesQueue table which has to be processed into orders to ship out.
Following this example, I need to notify a C# application that a new record has been inserted into the Queue table. I've read a number of articles regarding Service Broker and it seems like a good path, but I haven't found a good example of Insert record into a table and then notify a C# application then process.
Additionally I have these questions: 1) what is the best way to continuously run (or run on demand) this C# application, windows service, a command prompt application thats listening etc? 2) is there a good way to process this queue from multiple sources, aka the C# application I write could be run on many different machines and process through a queue?
Upvotes: 3
Views: 1757
Reputation: 4564
The feature you need is called external activation - there is a download from MS that allows you to configure a windows service to point to a queue and trigger an executable when messages arrive.
Upvotes: 2
Reputation: 3149
I suggest you take a look at messaging protocols like AMQP and an implementation like RabbitMQ.
If you have control over the sources, you can get them to write to RabbitMQ. Then have as many as consumers you want to read from RabbitMQ.
If you don't have the option to get the sources write to RabbitMQ, you can write your C# code to run as service and get the new records from database and push them to RabbitMQ.
Regarding your specific questions: 1) If the interval that you need to check the database is on order of seconds or less then I suggest a windows service, but if it is more than that, like minutes or hours then I suggest you write a C# console program and schedule it using windows scheduler.
2) As I mentioned I suggest you use an implementation of AMQP and don't reinvent the wheel. RabbitMQ has C# client out of the box.
Upvotes: 0