I have an issue coming up with the appropriate workflow and tools for communicating between Python scripts. The following is a rough diagram of what I'd like to achieve.
The idea is to have a main script which receives data, analyses it and sends a request to an already running chosen script. This script would then run a command upon receiving the message. I've searched around and the solutions I've seen included using sockets, ZeroMQ or RabbitMQ, admittedly I haven't looked too deeply into them but they seem to be two-way communications whereas I think I would need a one-to-many type communication.
Could someone recommend the most obvious tools for achieving something like this?
Thanks a lot
CodePudding user response:
- MQTT: Let your "workers" subscribe on a channel, one possibility to have a channel per script, another is to have single channel and message would have a prefix to differentiate for whom the message is. Your main script then publish on this/these channel/s.
- Make all scripts listen on a port, main script then connect to this port, use UDP or TCP as it would fit.
- Create an file per task in some directory, scripts would check these directories, pick up task and deletes the file then.
- Use common database with tasks. Careful with concurrent access to database.
CodePudding user response:
zeromq works well and is very simple to setup (no brokers/config etc)
- Script #4 creates a PUB socket and binds on port 12345
- Scripts #1-#3 create a SUB socket and connect 12345
- Scripts #1-#3 subscribe with their own ID (e.g 1 to 3)
- Script #4 Publishes the request with the ID of the worker who should receive it.