Skip to content

Commit f742e60

Browse files
committed
common-lisp: tutorial five code
1 parent 1790bd1 commit f742e60

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

common-lisp/emit-log-topic.lisp

+18
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/receive-logs-topic.lisp

+27
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

0 commit comments

Comments
 (0)