Skip to content

Commit b605415

Browse files
Merge pull request #88 from cl-rabbit/cl-bunny
Common Lisp tutorials
2 parents bed96f8 + cba1f15 commit b605415

14 files changed

+363
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ venv/*
1717
ruby*/rubygems*
1818

1919
java*/.idea/workspace.xml
20-
java*/.idea/encodings.xml
20+
java*/.idea/encodings.xml
21+
*~

common-lisp/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Common Lisp code for RabbitMQ tutorials
2+
3+
Here you can find Common Lisp code examples from
4+
[RabbitMQ tutorials](http://cl-rabbit.io/cl-bunny/tutorials/).
5+
6+
## Requirements
7+
8+
To run this code you need [Cl-Bunny](http://cl-rabbit.io/cl-bunny).
9+
10+
You can install it via Quicklisp:
11+
12+
(ql:quickload :cl-bunny)
13+
14+
Note: Cl-Bunny developed and tested using x64 sbcl on GNU/Linux
15+
16+
All our examples are in fact executable sbcl scripts. You can run them from command line
17+
18+
## Code
19+
20+
[Tutorial one: "Hello World!"](http://cl-rabbit.io/cl-bunny/tutorials/tutorial-one-cl.html):
21+
22+
./send.lisp
23+
./receive.lisp
24+
25+
[Tutorial two: Work Queues](http://cl-rabbit.io/cl-bunny/tutorials/tutorial-two-cl.html):
26+
27+
./new-task.lisp
28+
./worker.lisp
29+
30+
[Tutorial three: Publish/Subscribe](http://cl-rabbit.io/cl-bunny/tutorials/tutorial-three-cl.html)
31+
32+
./receive-logs.lisp
33+
./emit-log.lisp
34+
35+
[Tutorial four: Routing](http://cl-rabbit.io/cl-bunny/tutorials/tutorial-four-cl.html)
36+
37+
./receive-logs-direct.lisp
38+
./emit-log-direct.lisp
39+
40+
[Tutorial five: Topics](http://cl-rabbit.io/cl-bunny/tutorials/tutorial-five-cl.html)
41+
42+
./receive-logs-topic.lisp
43+
./emit-log-topic.lisp
44+
45+
[Tutorial six: RPC](http://cl-rabbit.io/cl-bunny/tutorials/tutorial-six-cl.html)
46+
47+
./rpc-server.lisp
48+
./rpc-client.lisp
49+
50+
To learn more, visit [Cl-Bunny documentation](http://cl-rabbit.io/cl-bunny) site.

common-lisp/emit-log-direct.lisp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
sbcl --noinform --noprint $@ <<EOF
4+
5+
(ql:quickload :cl-bunny.examples)
6+
7+
(in-package :cl-bunny.examples)
8+
9+
(with-connection ()
10+
(with-channel ()
11+
(let* ((args (rest sb-ext:*posix-argv*))
12+
(severity (or (first args) "info"))
13+
(msg (format nil "~{~a~^ ~}" (rest args)))
14+
(x (exchange.direct "direct_logs")))
15+
(publish x msg :routing-key severity)
16+
(format t " [x] Sent '~a'~%" msg))))
17+
18+
EOF

common-lisp/emit-log-topic.lisp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
sbcl --noinform --noprint $@ <<EOF
4+
5+
(ql:quickload :cl-bunny.examples)
6+
7+
(in-package :cl-bunny.examples)
8+
9+
(with-connection ()
10+
(with-channel ()
11+
(let* ((args (rest sb-ext:*posix-argv*))
12+
(severity (or (first args) "info"))
13+
(msg (format nil "~{~a~^ ~}" (rest args)))
14+
(x (exchange.topic "topic_logs")))
15+
(publish x msg :routing-key severity)
16+
(format t " [x] Sent '~a'~%" msg))))
17+
18+
EOF

common-lisp/emit-log.lisp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
sbcl --noinform --noprint $@ <<EOF
4+
5+
(ql:quickload :cl-bunny.examples)
6+
7+
(in-package :cl-bunny.examples)
8+
9+
(with-connection ("amqp://")
10+
(with-channel ()
11+
(let ((msg (format nil "~{~a~^ ~}" (cdr sb-ext:*posix-argv*)))
12+
(x (exchange.fanout "logs")))
13+
(publish x msg)
14+
(format t " [x] Sent '~a'~%" msg))))
15+
16+
EOF

common-lisp/new-task.lisp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
sbcl --noinform --noprint $@ <<EOF
4+
5+
(ql:quickload :cl-bunny.examples)
6+
7+
(in-package :cl-bunny.examples)
8+
9+
(with-connection ()
10+
(with-channel ()
11+
(let ((x (exchange.default))
12+
(msg (format nil "~{~a~^ ~}" (cdr sb-ext:*posix-argv*))))
13+
(publish x msg :routing-key "task_queue"
14+
:properties '(:persistent t))
15+
(format t " [x] Sent '~a'~%" msg))))
16+
17+
EOF

common-lisp/receive-logs-direct.lisp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
sbcl --noinform --noprint $@ <<EOF
4+
5+
(ql:quickload :cl-bunny.examples)
6+
7+
(in-package :cl-bunny.examples)
8+
9+
(if-let ((args (rest sb-ext:*posix-argv*)))
10+
(with-connection ()
11+
(with-channel ()
12+
(let ((q (queue.declare :auto-delete t))
13+
(x (exchange.direct "direct_logs")))
14+
(loop for severity in args do
15+
(queue.bind q x :routing-key severity))
16+
(format t " [*] Waiting for logs. To exit press CTRL+C~%")
17+
(handler-case
18+
(progn
19+
(subscribe q (lambda (message)
20+
(format t " [x] #~a:~a~%" (message-routing-key message) (message-body-string message)))
21+
:type :sync)
22+
(consume))
23+
(sb-sys:interactive-interrupt ()
24+
(sb-ext:exit))))))
25+
(format t "Usage: $0 [info] [warning] [error]~%"))
26+
27+
EOF

common-lisp/receive-logs-topic.lisp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
sbcl --noinform --noprint $@ <<EOF
4+
5+
(ql:quickload :cl-bunny.examples)
6+
7+
(in-package :cl-bunny.examples)
8+
9+
(if-let ((args (rest sb-ext:*posix-argv*)))
10+
(with-connection ()
11+
(with-channel ()
12+
(let ((q (queue.declare :auto-delete t))
13+
(x (exchange.topic "topic_logs")))
14+
(loop for severity in args do
15+
(queue.bind q x :routing-key severity))
16+
(format t " [*] Waiting for logs. To exit press CTRL+C~%")
17+
(handler-case
18+
(progn
19+
(subscribe q (lambda (message)
20+
(format t " [x] #~a:~a~%" (message-routing-key message) (message-body-string message)))
21+
:type :sync)
22+
(consume))
23+
(sb-sys:interactive-interrupt ()
24+
(sb-ext:exit))))))
25+
(format t "Usage: $0 [binding key]~%"))
26+
27+
EOF

common-lisp/receive-logs.lisp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
sbcl --noinform --noprint <<EOF
4+
5+
(ql:quickload :cl-bunny.examples)
6+
7+
(in-package :cl-bunny.examples)
8+
9+
(with-connection ("amqp://")
10+
(with-channel ()
11+
(let ((q (queue.declare-temp)))
12+
(queue.bind q "logs")
13+
(format t " [*] Waiting for logs. To exit press CTRL+C~%")
14+
(handler-case
15+
(progn
16+
(subscribe q (lambda (message)
17+
(format t " [x] #~a~%" (message-body-string message)))
18+
:type :sync)
19+
(consume))
20+
(sb-sys:interactive-interrupt ()
21+
(sb-ext:exit))))))
22+
23+
EOF

common-lisp/receive.lisp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
sbcl --noinform --noprint <<EOF
4+
5+
(ql:quickload :cl-bunny.examples)
6+
7+
(in-package :cl-bunny.examples)
8+
9+
(with-connection ("amqp://")
10+
(with-channel ()
11+
(let ((q (queue.declare :name "hello")))
12+
(format t " [*] Waiting for messages in queue 'hello'. To exit press CTRL+C~%")
13+
(handler-case
14+
(progn
15+
(subscribe q (lambda (message)
16+
(format t " [x] Received ~a~%" (message-body-string message)))
17+
:type :sync
18+
:no-ack t)
19+
(consume))
20+
(sb-sys:interactive-interrupt ()
21+
(sb-ext:exit))))))
22+
23+
EOF

0 commit comments

Comments
 (0)