Skip to content

Commit

Permalink
common-lisp: tutorial four code
Browse files Browse the repository at this point in the history
  • Loading branch information
deadtrickster committed Mar 2, 2016
1 parent 6aa023e commit 1790bd1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions common-lisp/emit-log-direct.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

sbcl --noinform --noprint $@ <<EOF
(ql:quickload :cl-bunny.examples)
(in-package :cl-bunny.examples)
(with-connection ()
(with-channel ()
(let* ((args (rest sb-ext:*posix-argv*))
(severity (or (first args) "info"))
(msg (format nil "~{~a~^ ~}" (rest args)))
(x (exchange.direct "direct_logs")))
(publish x msg :routing-key severity)
(format t " [x] Sent '~a'~%" msg))))
EOF
27 changes: 27 additions & 0 deletions common-lisp/receive-logs-direct.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

sbcl --noinform --noprint $@ <<EOF
(ql:quickload :cl-bunny.examples)
(in-package :cl-bunny.examples)
(if-let ((args (rest sb-ext:*posix-argv*)))
(with-connection ()
(with-channel ()
(let ((q (queue.declare :auto-delete t))
(x (exchange.direct "direct_logs")))
(loop for severity in args do
(queue.bind q x :routing-key severity))
(format t " [*] Waiting for logs. To exit press CTRL+C~%")
(handler-case
(progn
(subscribe q (lambda (message)
(format t " [x] #~a:~a~%" (message-routing-key message) (message-body-string message)))
:type :sync)
(consume))
(sb-sys:interactive-interrupt ()
(sb-ext:exit))))))
(format t "Usage: $0 [info] [warning] [error]~%"))
EOF

0 comments on commit 1790bd1

Please sign in to comment.