common-lisp: tutorial two code

This commit is contained in:
Ilya Khaprov 2016-03-02 03:24:16 -08:00
parent 5164733308
commit ccbf823a38
2 changed files with 45 additions and 0 deletions

17
common-lisp/new-task.lisp Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
sbcl --noinform --noprint $@ <<EOF
(ql:quickload :cl-bunny.examples)
(in-package :cl-bunny.examples)
(with-connection ()
(with-channel ()
(let ((x (exchange.default))
(msg (format nil "~{~a~^ ~}" (cdr sb-ext:*posix-argv*))))
(publish x msg :routing-key "task_queue"
:properties '(:persistent t))
(format t " [x] Sent '~a'~%" msg))))
EOF

28
common-lisp/worker.lisp Executable file
View File

@ -0,0 +1,28 @@
#!/bin/sh
sbcl --noinform --noprint <<EOF
(ql:quickload :cl-bunny.examples)
(in-package :cl-bunny.examples)
(with-connection ()
(with-channel ()
(let ((q (queue.declare :name "task_queue" :durable t)))
(format t " [*] Waiting for messages in queue 'task_queue'. To exit press CTRL+C~%")
(qos :prefetch-count 1)
(handler-case
(progn
(subscribe q (lambda (message)
(let ((body (message-body-string message)))
(format t " [x] Received '~a'~%" body)
;; imitate some work
(sleep (count #\. body))
(message.ack message)
(format t " [x] Done~%")))
:type :sync)
(consume))
(sb-sys:interactive-interrupt ()
(sb-ext:exit))))))
EOF