-
Notifications
You must be signed in to change notification settings - Fork 2
/
examples.lisp
66 lines (54 loc) · 1.61 KB
/
examples.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
;;; connect server
(let ((sokt (connect-nats-server "127.0.0.1")))
(read-nats-stream-answer-ping sokt))
;;; connect server and get info
(multiple-value-bind (sokt info)
(connect-nats-server "127.0.0.1")
(format t "hashtable info ~a~%" info)
(read-nats-stream-answer-ping sokt))
;;; subscribe
(let* (sokt
info
)
(multiple-value-setq (sokt info) (connect-nats-server "127.0.0.1"))
(nats-subs sokt
"test"
1
(lambda (x) (progn (print "inner consume function") (print x)))
:info info
))
;;; with queue group
(let* (sokt
info
)
(multiple-value-setq (sokt info) (connect-nats-server "127.0.0.1"))
(nats-subs sokt
"test"
1
(lambda (x) (progn (print "inner consume function") (print x)))
:info info
:queue-group 23
))
;;; publish message
(let* (sokt
info
)
(multiple-value-setq (sokt info) (connect-nats-server "127.0.0.1"))
(nats-pub sokt
"test"
5
"hello"
))
;;; write you own message handler
(let (sokt
info)
(multiple-value-setq (sokt info) (connect-nats-server "127.0.0.1"))
;; with-nats-stream macro will read message in stream one by one
;; then binding message with data which used in body
;; sokt will close when with-nats-stream macro finish
(with-nats-stream (sokt data)
(format t "~a~%" data)))
;;; Connect with creds file
(multiple-value-bind (sokt info)
(connect-nats-server "127.0.0.1" :cred "your creds file")
(read-nats-stream-answer-ping sokt))