Git Product home page Git Product logo

clj-nats's Introduction

clj-nats

A Clojure library for NATS.

Usage

This library is available on Clojars:

Clojars Project

clj-nats is based on java-nats and is very much a work in progress. Feedback and contributions are appreciated.

Here's an example of typical usage:

(require '[clojure.tools.logging :as log])
(require '[clj-nats.core :as nats])
(require '[com.stuartsierra.component :as component]))

(def system (component/system-map
             :connection
             (nats/connection ["nats://localhost:4222"])
             :foo-sub
             (component/using
              (nats/subscription
               "foo"
               [#(log/infof "To this I say \"foo\": %s" (.getBody %))])
              [:connection])
             :helper-sub
             (component/using
              (nats/subscription
               "help"
               [(fn [m]
                  (log/infof "Got help request: %s" (.getBody m))
                  (.reply m "Umm, are you connected to the network?"))])
              [:connection])))

(defn start-system []
  (alter-var-root #'system component/start))

(defn stop-system []
  (alter-var-root #'system component/stop))

(defn exercise-system []
  (log/info "Starting exercise regime.")
  (start-system)

  (nats/publish (:connection system) "foo" "yo")
  
  (nats/request (:connection system) "help" "I can't find the printer." nil
                #(log/infof "Ooh, a response: %s" (.getBody %)))
  
  (log/info "Waiting a few seconds to let things play out.")
  (java.lang.Thread/sleep 5000)

  (stop-system)
  (log/info "Finished exercise regime."))

License

Copyright © 2014 Edwin Watkeys

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

clj-nats's People

Contributors

edw avatar

Watchers

 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.