forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc-client.lisp
executable file
·46 lines (39 loc) · 1.45 KB
/
rpc-client.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
sbcl --noinform --noprint <<EOF
(ql:quickload :cl-bunny.examples)
(ql:quickload :nibbles)
(in-package :cl-bunny.examples)
(defun int64-to-octets(val)
(let ((obuffer (fast-io:make-output-buffer)))
(fast-io:write64-be val obuffer)
(fast-io:finish-output-buffer obuffer)))
(defun start-client (n)
(with-connection ("amqp://")
(with-channel ()
(let ((x (exchange.default))
(server-queue "rpc_queue")
(reply-queue (queue.declare :auto-delete t))
(lock (bt:make-lock))
(condition (bt:make-condition-variable))
(result nil))
(format t " [x] Requesting fib(~a)~%" n)
(bt:with-lock-held (lock)
(subscribe reply-queue (lambda (message)
(bt:with-lock-held (lock)
(setf result (nibbles:sb64ref/be (message-body message) 0))
(bt:condition-notify condition))))
(publish x
(int64-to-octets n)
:routing-key server-queue
:properties (list :correlation-id (format nil "~a~a~a" (random 100) (random 100) (random 100))
:reply-to reply-queue))
(bt:condition-wait condition lock)
(format t " [.] Got ~a~%" result)
result)))))
(start-client 0)
(start-client 1)
(start-client 22)
(start-client 33)
(start-client 44)
(start-client 55)
EOF