I have Perl script that currently does some background stuff, and I need the results in Python for a web front end. I want to use JSON to do this, or somthing similar but I am not sure how to go about it.

My JSON could look like this...

{
  "array": [
    1,
    2,
    3
  ],
  "boolean": true,
  "null": null,
  "number": 123,
  "object": {
    "a": "b",
    "c": "d",
    "e": "f"
  },
  "string": "Hello World"
}

And I want to send that this from Perl to Python...

I was thinking about using a message queue where Perl returns the JSON objects to Redis and my Python app retrieves it.

Is this possible, is there a better way?

有帮助吗?

解决方案

Redis as message broker

Your idea of Redis as message broker sound good. Redis also offers publish subscribe, you publish a message (e.g. JSON object) into a channel and whoever is currently subscribed can consume it (all consumers can get all messages published during their subscription).

ZeroMQ as lightweight messaging solution

Other solution is to provide the message via ZeroMQ. There are bindings for Perl and Python (and many other languages), any binary data can be sent (what includes your JSON), and there are many messaging patterns available (request/response, publish/subscribe, push/pull etc).

Check samples of code for Python and Perl, you will be surprised, how simple and short the code could be (while it will provide very stable and flexible solution)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top