Common Lisp RabbitMQ client based on IOLib
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
src
t
.gitignore
.travis.yml
CONTRIBUTORS.md
LICENSE
README.md
TODO.org
cl-bunny.asd
cl-bunny.examples.asd
cl-bunny.test.asd
install-travis-deps.sh

README.md

CL-BUNNY Build Status Coverage Status

CL-BUNNY is a RabbitMQ client. CL-BUNNY is based on IOLib and inspired by bunny and pika.

Installation Notes

Since March 2016 CL-BUNNY can be installed using Quicklisp

(ql:quickload :cl-bunny)

You can also checkout releases list

Examples

Foreword

To run examples you need to have RabbitMQ installed on localhost with

  • vhost /
  • user named guest with password guest.

If you are new to RabbitMQ you may find the following links useful:

Hello World!

(defun hello-world ()
  (with-connection ()
    (with-channel ()
      (let ((x (exchange.default)))
        (->
          (queue.declare :name "cl-bunny.examples.hello-world" :auto-delete t)
          (subscribe (lambda (message)
                       (log:info "Received ~a"
                                 (message-body-string message)))))
        (publish x "Hello world!" :routing-key "cl-bunny.examples.hello-world"))
      (sleep 1))))

Error handling

(with-connection ()
  (with-channel ()
    (handler-case
        (channel.open)
      (connection-closed-error () (print "Can't open already opened channel")))))
-->
<WARN> [17:10:39] bunny iolib-threaded.lisp (channel.receive threaded-iolib-connection amqp-method-connection-close) -
 Connection closed by server: AMQP-ERROR-CHANNEL-ERROR[504, CHANNEL_ERROR - second 'channel.open' seen] in response to AMQP-METHOD-CHANNEL-OPEN
"Can't open already opened channel"
"Can't open already opened channel"

Headers Exchange

(with-connection ()
  (with-channel ()
    (let* ((x (exchange.headers "headers" :auto-delete t))
           (q1 (->
                 (queue.declare :exclusive t)
                 (queue.bind x :arguments '(("os" . "linux")
                                            ("cores" . 8)
                                            ("x-match" . "all")))))
           (q2 (->
                 (queue.declare :exclusive t)
                 (queue.bind x :arguments '(("os" . "osx")
                                            ("cores" . 4)
                                            ("x-match" . "any"))))))
      (subscribe q1 (lambda (message)
                      (log:info "~a received ~a" q1 (message-body-string message))))


      (subscribe q2 (lambda (message)
                      (log:info "~a received ~a" q2 (message-body-string message))))

      (publish x "8 cores/Linux" :properties '(:headers (("os" . "linux")
                                                       ("cores" . 8))))
      (publish x "8 cores/Linux" :properties '(:headers (("os" . "linux")
                                                       ("cores" . 8))))
      (publish x "8 cores/OS X"  :properties '(:headers (("os" . "osx")
                                                       ("cores" . 8))))
      (publish x "4 cores/Linux" :properties '(:headers (("os" . "linux")
                                                       ("cores" . 4))))

      (log:info "Waiting...")
      (sleep 3)
      (log:info "Disconnecting"))))

Mandatory messages

(with-connection ()
  (with-channel ()
    (let* ((x (exchange.default))
           (q (queue.declare :exclusive t)))

      (setf (exchange-on-return-callback x)
            (lambda (returned-message)
              (log:info "Got returned message ~a" (message-body-string returned-message))))

      (subscribe q (lambda (message)                       
                     (log:info "~a received ~a" q (message-body-string message))))

      (publish x "This will NOT be returned" :mandatory t :routing-key q)
      (publish x "This will be returned" :mandatory t
                                         :routing-key (format nil "wefvvtrw~a" (random 10)))        

      (log:info "Waiting...")
      (sleep 3)
      (log:info "Disconnecting"))))

More?

More examples can be found here

Special Thanks To

Copyright

Copyright (c) 2015,2016 Ilya Khaprov ilya.khaprov@publitechs.com and CONTRIBUTORS

CL-BUNNY uses a shared copyright model: each contributor holds copyright over their contributions to CL-BUNNY. The project versioning records all such contribution and copyright details.

If a contributor wants to further mark their specific copyright on a particular contribution, they should indicate their copyright solely in the commit message of the change when it is committed. Do not include copyright notices in files for this purpose.

License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

By contributing to the project, you agree to the license and copyright terms therein and release your contribution under these terms.