Skip to content

Commit

Permalink
Tutorial 1 in Clojure
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Klishin committed Aug 4, 2013
1 parent 54f5aac commit 3c99326
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
10 changes: 10 additions & 0 deletions clojure/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/target
/lib
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
.lein-*
bin/*
48 changes: 48 additions & 0 deletions clojure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Clojure code for RabbitMQ tutorials

Here you can find Ruby code examples from
[RabbitMQ tutorials](http://www.rabbitmq.com/getstarted.html).

## Requirements

To run this code you need [Langohr](http://clojurerabbitmq.info).

Dependencies are managed by [Leiningen](http://leiningen.org).

These tutorials only require JDK 6 or 7 (Oracle or OpenJDK).

## Code

Code examples are executed via `lein run`:

[Tutorial one: "Hello World!"](http://www.rabbitmq.com/tutorial-one-java.html):

lein run -m "rabbitmq.tutorials.send"
lein run -m "rabbitmq.tutorials.receive"

[Tutorial two: Work Queues](http://www.rabbitmq.com/tutorial-two-java.html):

lein run -m "rabbitmq.tutorials.new-task"
lein run -m "rabbitmq.tutorials.worker"

[Tutorial three: Publish/Subscribe](http://www.rabbitmq.com/tutorial-three-java.html)

ruby receive_logs.rb
ruby emit_log.rb

[Tutorial four: Routing](http://www.rabbitmq.com/tutorial-four-java.html)

ruby receive_logs_direct.rb
ruby emit_log_direct.rb

[Tutorial five: Topics](http://www.rabbitmq.com/tutorial-five-java.html)

ruby receive_logs_topic.rb
ruby emit_log_topic.rb

[Tutorial six: RPC](http://www.rabbitmq.com/tutorial-six-java.html)

ruby rpc_server.rb
ruby rpc_client.rb

To learn more, visit [Langohr documentation](http://clojurerabbitmq.info) site.
7 changes: 7 additions & 0 deletions clojure/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(defproject com.rabbitmq/tutorials "1.0.0-SNAPSHOT"
:description "RabbitMQ tutorials using Langohr"
:url "http://github.com/rabbitmq/rabbitmq-tutorial"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[com.novemberain/langohr "1.3.0"]])
18 changes: 18 additions & 0 deletions clojure/src/rabbitmq/tutorials/receive.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns rabbitmq.tutorials.receive
(:require [langohr.core :as lc]
[langohr.channel :as lch]
[langohr.queue :as lq]
[langohr.consumers :as lcons]))

(defn handle-delivery
"Handles message delivery"
[ch metadata payload]
(println (format " [x] Received %s" (String. payload "UTF-8"))))

(defn -main
[& args]
(with-open [conn (lc/connect)]
(let [ch (lch/open conn)]
(lq/declare ch "hello" :durable false :auto-delete false)
(println " [*] Waiting for messages. To exit press CTRL+C")
(lcons/blocking-subscribe ch "hello" handle-delivery :auto-ack true))))
14 changes: 14 additions & 0 deletions clojure/src/rabbitmq/tutorials/send.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(ns rabbitmq.tutorials.send
(:require [langohr.core :as lc]
[langohr.channel :as lch]
[langohr.queue :as lq]
[langohr.basic :as lb]))


(defn -main
[& args]
(with-open [conn (lc/connect)]
(let [ch (lch/open conn)]
(lq/declare ch "hello" :durable false :auto-delete false)
(lb/publish ch "" "hello" (.getBytes "Hello World!" "UTF-8"))
(println " [x] Sent 'Hello World!'"))))

0 comments on commit 3c99326

Please sign in to comment.