common-lisp: tutorial two code
This commit is contained in:
parent
5164733308
commit
ccbf823a38
17
common-lisp/new-task.lisp
Executable file
17
common-lisp/new-task.lisp
Executable 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
28
common-lisp/worker.lisp
Executable 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
|
Loading…
Reference in New Issue
Block a user