/[de-setf-amqp]/rabbitmq/examples.lisp
ViewVC logotype

Contents of /rabbitmq/examples.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations)
Tue Feb 23 09:05:39 2010 UTC (4 years, 1 month ago) by janderson
File size: 4203 byte(s)
Merge commit 'remotes/github/master' into remotes/git-svn
1 ;;;-* Package: rabbitmq; -*-
2
3 (in-package :rabbitmq)
4
5 ;; EXAMPLES.LISP
6 ;; Nick Levine, Ravenbrook Limited, 2007-09-04
7 ;; James Anderson, setf.de, 2010-02-04
8
9 ;; 1. INTRODUCTION
10 ;;
11 ;; The purpose of this document demonstrate the RABBITMQ package.
12 ;;
13 ;; See Appendix C below for copyright and license.
14
15 ;; This transcript paraphrases Levine's original README, with results as per emulation.
16 ;; It opens a connection and a channel, declares exchange and queue, binds them and
17 ;; loops a message back to itself.
18
19 (defparameter *my-connection* nil)
20 (defparameter *my-channel* nil)
21 (defparameter *outgoing-message* nil)
22 (defparameter *incoming-message* nil)
23
24 (setq *my-connection* (new-connection "localhost" "/"))
25 ;; #<AMQP-1-1-0-9-1:CLIENT-CONNECTION #x278956FE>
26
27 (setq *my-channel* (new-channel *my-connection*))
28 ;; #<CHANNEL [#<URI amqp://localhost:5672/>].1 #x278C33FE>
29
30
31 (declare-exchange *my-channel* "my exchange" :direct)
32 ;; #<AMQP-1-1-0-9-1:EXCHANGE #x27A3C2FE>
33
34 (declare-queue *my-channel* "my queue")
35 ;; #<AMQP-1-1-0-9-1:QUEUE #x27C8E346>
36
37 (bind-queue *my-channel* "my queue" "my exchange" "my routing key")
38 ;; #<AMQP-1-1-0-9-1:QUEUE #x27C8E346>
39
40
41 ;;; - Send a message into the void:
42 (setq *outgoing-message* (new-message))
43 ;; #<OUTGOING-MESSAGE #x27CBAFEE>
44
45
46 (setf (message-id *outgoing-message*) "42"
47 (message-body *outgoing-message*) "Hello, World")
48 ;; "Hello, World"
49
50
51 (publish *outgoing-message* *my-channel* "my exchange" "my routing key")
52 ;; "Hello, World"
53
54
55 ;;; - And get it back again:
56 (consume-queue *my-channel* "my queue")
57 ;; #<CHANNEL [#<URI amqp://localhost:5672/>].1 #x2B5691F6>
58
59 (channel-arrived-count *my-channel*)
60 ;; 1
61
62 (setq *incoming-message* (next-message *my-channel*))
63 ;; #<RABBITMQ::QUEUEINGCONSUMER$DELIVERY #x2B7F9486>
64
65 (values (message-body *incoming-message*)
66 (message-id *incoming-message*))
67 ;; "Hello, World"
68 ;; ""
69
70 (close *my-connection* :abort t)
71
72
73 ;; A. REFERENCES
74 ;; [1] [org.levine.rabbitmq](http://www.nicklevine.org/cl-rabbit/)
75 ;;
76 ;; B. HISTORY
77 ;;
78 ;; 2007-09-21 NDL Created.
79 ;; 2009-02-04 james.anderson@setf.de portability
80 ;;
81 ;;
82 ;; C. COPYRIGHT
83 ;;
84 ;; Copyright (c) 2007 Wiinz Limited.
85 ;;
86 ;; Permission is hereby granted, free of charge, to any person
87 ;; obtaining a copy of this software and associated documentation
88 ;; files (the "Software"), to deal in the Software without
89 ;; restriction, including without limitation the rights to use, copy,
90 ;; modify, merge, publish, distribute, sublicense, and/or sell copies
91 ;; of the Software, and to permit persons to whom the Software is
92 ;; furnished to do so, subject to the following conditions:
93 ;;
94 ;; The above copyright notice and this permission notice shall be
95 ;; included in all copies or substantial portions of the Software.
96 ;;
97 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
98 ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
99 ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
100 ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
101 ;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
102 ;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
103 ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
104 ;; DEALINGS IN THE SOFTWARE.
105
106 ;;;
107 ;;; This file is part of the `de.setf.amqp.rabbitmq` library module.
108 ;;; It contains examples for simple interaction with a broker.
109 ;;; (c) 2010 [james anderson](mailto:james.anderson@setf.de)
110 ;;;
111 ;;; `de.setf.amqp.rabbitmq` is free software: you can redistribute it and/or modify
112 ;;; it under the terms of the GNU General Public License as published by
113 ;;; the Free Software Foundation, as version 3 of the License.
114 ;;;
115 ;;; `de.setf.amqp.rabbitmq` is distributed in the hope that it will be useful,
116 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
117 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118 ;;; GNU General Public License for more details.
119 ;;;
120 ;;; You should have received a copy of the GNU General Public License
121 ;;; along with `de.setf.amqp.rabbitmq`. If not, see the GNU [site](http://www.gnu.org/licenses/).
122
123
124 ;;; 2010-02-03 [janderson](james.anderson@setf.de)

  ViewVC Help
Powered by ViewVC 1.1.5