Skip to content

Commit ccbf823

Browse files
committed
common-lisp: tutorial two code
1 parent 5164733 commit ccbf823

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

common-lisp/new-task.lisp

+17
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/worker.lisp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 ((q (queue.declare :name "task_queue" :durable t)))
12+
(format t " [*] Waiting for messages in queue 'task_queue'. To exit press CTRL+C~%")
13+
(qos :prefetch-count 1)
14+
(handler-case
15+
(progn
16+
(subscribe q (lambda (message)
17+
(let ((body (message-body-string message)))
18+
(format t " [x] Received '~a'~%" body)
19+
;; imitate some work
20+
(sleep (count #\. body))
21+
(message.ack message)
22+
(format t " [x] Done~%")))
23+
:type :sync)
24+
(consume))
25+
(sb-sys:interactive-interrupt ()
26+
(sb-ext:exit))))))
27+
28+
EOF

0 commit comments

Comments
 (0)