Giter Site home page Giter Site logo

snakepit's Introduction

This is a quick and dirty demonstration of how Python and Clojure can communicate with one another using rabbitmq.

The use case for me is that I'm writing a webapp in Clojure, and I want it to be backed by some machine learning, and of course Python has the best libraries for that kind of stuff. So, when I want to fit a model, I'm just going to send the data to python and let it send the result back to Clojure when it's done.

To run on your machine:

  1. Clone this repo.

  2. Install dependencies. For python, you'll need pika, pip install pika. You'll also need rabbitmq. brew install rabbitmq or the apt-get/whev equivalent. If you install via homebrew on mac, be aware that it lands in a place that isn't automatically on PATH for some silly reason.

  3. Fire up rabbitmq with /usr/local/sbin/rabbitmq-server

  4. Open up a new terminal window and fire up the python script with python talktoclojure.py

  5. Open up a third terminal window and lein run.

You should see Clojure send a message to Python which will print on the Python terminal, and then see Python send a reply to Clojure which will print on the Clojure terminal.

  1. To cleanly shut down, control-c out of the python terminal, and run /usr/local/sbin/rabbitmqctl stop to get rabbitmq to shut down --- keyboard interrupts won't do the trick for the last one. Clojure will shut itself down.

You can also just use the shell script talk.sh that will handle the details for you.

If you want to see how clj and python can exchange actual data in JSON format, that's in here too. Just use lein run json or ./talk.sh json

If you want to try out a version that wires the Clojure-side up with core.async, give it the commandline argument async instead of json.

Created using the basic leiningen app template, mostly following this tutorial on the Clojure-side and this tutorial on the Python-side, so, like, almost none of the code is actually mine, but any residual rights that I may have in, I dunno, the act of putting the two tutorials together or something, is hereby committed to the public domain.

Other useful info: this github issue explains why the default needs to be changed on the clojure-side to :auto-delete false. And this is a very nice general explainer for how rabbitmq works. I also looked at this, though didn't get too much from it.

snakepit's People

Contributors

paultopia avatar

Stargazers

pancy avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.