2

I have a asp.net core application "A" which generates files every 1 minute in a folder.

Application "B" wants a notification or file details what file we generated and some Hash information for that file. Based on this notification, Application "B" wants to process the files.

I am thinking of some pub/sub mechanism and I want very light weight components where Application "A" will publish the file related information and Application "B" will subscribe and listen.

Is "system.threading.channels" will solve this problem?

user584018
  • 10,186
  • 15
  • 74
  • 160
  • What you describe doesn't seem to have anything to do with pub/sub. – Panagiotis Kanavos Nov 25 '20 at 13:05
  • 2
    @PanagiotisKanavos that sounds very much like pub/sub to me... nothing to do with "channels", though – Marc Gravell Nov 25 '20 at 13:07
  • Thanks. That's my thoughts. Without pub/sub what are the ways? – user584018 Nov 25 '20 at 13:07
  • I need some pub/sub with zero installation, if possible. – user584018 Nov 25 '20 at 13:08
  • @MarcGravell it's inter-process communication through a shared folder. Yes, it's a publisher/subscriber problem, in the same way bikes and lorries are wheeled vehicles though. No in-process mechanism can work with the current question – Panagiotis Kanavos Nov 25 '20 at 13:09
  • 1
    @user584018 you're using `pub/sub` as if it is a specific library or technology. It's not, it's a very broad problem description that could even cover sending .... paper ballots. For starters, you can use a FileSystemWatcher to check when a new file is created. A better approach may be to have one application call the other's HTTP endpoint and send the entire file. – Panagiotis Kanavos Nov 25 '20 at 13:13
  • Are the two applications running on the same machine? Or on the same local network? – Theodor Zoulias Nov 25 '20 at 13:33
  • both applications running in same machine, both are dotnet core applications – user584018 Nov 25 '20 at 13:34
  • I would consider a file-based communication, which is low tech and easy to monitor. The application A would create two files each time, the main file and an `.info` file containing metadata about the main file. The application B would set a `FileSystemWatcher` observing the folder, with a filter for `.info` files. It would open each new `.info` file, would read the metadata, and then process the main file. – Theodor Zoulias Nov 28 '20 at 03:56

1 Answers1

6

Short version: no.

System.Threading.Channels is in-process - very similar to Queue<T> in many ways, but designed for async access; no part of that API allows IPC.

There are a number of ways of doing this cross-process (and potentially cross-machine), but the options that leap to mind would be:

  • have one of the nodes set up a socket server, and have the other node connect over sockets; send messages to each-other that way
  • the same, but with named pipes instead of sockets
  • the same, but with an http server; kestrel is pretty easy to setup as a server
  • using an external message broker or pipe as the intermediary, and have both nodes connect to that as clients
  • just detect changes to the file system
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900