How to have a sequence of Windows Services

Viewed 82

The solution I am working on requires multiple processes that are built in multiple Windows services all built using C# running on .NET.

  • Service 1 : Extract data in files in a folder
  • Service 2 : Analyse data and put results in image file
  • Service 3 : Process images into another application
  • Service 4 : Generate report

Each service runs every hour. Everything works fine.

One of the requests now is to do all services as fast as possible. Therefore I want these services to run consecutively.

How to call one service from the other or have a pipeline that runs all services one after the other.

2 Answers

You can use a message queue. I recommend RabbitMQ. It is simple. By the your business flow each service listens its pipeline/queue. For example Service1 extracts data from files then sends a message to Service2’s queue. Service2 gets the message and runs its task, after completes its task sends a message to Service3... You can build a flow ilke this with RabbitMQ.

You could use FileSystemWatcher and use folders as simple queues between services. Also note, FileSystemWatcher might not be 100% Reliable: FileSystemWatcher vs polling to watch for file changes

Might need to set the NotifyFilter to get the behaviour you want.

You could also add a mutex to the service, that detects if it is already running perhaps, and consumes folder/file changes in one go.

There are other heavier weight, fully featured message queues, but these might be overkill for your needs.

Related