I would like to have the same service on multiple servers watching a single directory (on a shared server or SAN). When a file appears in that directory I want one, and only one of those services to pick up that file and process its contents.
I attempted to program this by moving the file out of the shared directory before processing it. I am fine with simply handling the exception on whichever server fails to move the file. The problem is that conflicts occur and cause the file not to be processed by either server.
It is likely that files will arrive in batch开发者_如何学JAVAes, not one by one. Does anyone know an approach to this that will work in a guaranteed way?
Try having one 'master' service with a FSW. The master service processes all FSW events and commands 'slave' services on remote machines to handle a certain file. Easy load balancing, no multiple FSW issues, no database needed. You could easily accomplish this with WCF.
I would have only one server/service monitoring that folder and writing in a database filepath and changed date and event (copy,rename...) then you can have all services you want to grab one of those recent new records in that table, lock it and processing it. Basically since FSW is working badly with concurrency we move concurrency handling to the database.
i will also suggest the solution form Davide Piras. But if you still want to have the file watcher application in multiple servers looking for shared directory then one solution comes in mind is that you create the tcp connections between your file watcher application, as any file arrives in the shared dir then all file watcher applications generates random number and share that number with each other, then the application generated largest (or smallest) number should process that file. In this way only one file watcher application will process the file
精彩评论