Search code examples
c#asp.net-coresystem.threading.channels

Is "system.threading.channels" will solve the pub sub problem for cross process applications


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?


Solution

  • 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