Commit 107259b0 authored by Francois-Rene Rideau's avatar Francois-Rene Rideau
Browse files

Improvements to the CL-STOMP library, by Scott McKay <swm@itasoftware.com>

 - Make the API functions more robust against bad inputs
 - Fix some inefficiencies
 - Generally make it use better Lisp style
 - Get the example code working

Testing: The STOMP tests that Matt already wrote still work correctly.
parent 53557988
Loading
Loading
Loading
Loading
+4 −3
Changes for cl-stomp-example.asd: 4 added lines, 3 removed lines.
Original line number Diff line number Diff line
;; -*- mode: lisp; -*-

(in-package :asdf)

(defsystem :example
    :version "0.1.0"
    :depends-on (cl-ppcre cl-stomp)
    :components
    ((:file "example")))
    :depends-on (cl-stomp)
    :components ((:file "example")))
+3 −5
Changes for cl-stomp.asd: 3 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -7,10 +7,8 @@

(defsystem cl-stomp
  :description "Implements the STOMP protocol for connecting to a message broker."
  :author ""
  :author "Keith Irwin, Matt Reklaitis"
  :version ""
  :licence ""
  :depends-on (cl-ppcre usocket)
  :licence "MIT-style License"
  :depends-on (usocket)
  :components ((:file "cl-stomp")))

+279 −264

File changed.

Preview size limit exceeded, changes collapsed.

+14 −14
Changes for example.lisp: 14 added lines, 14 removed lines.
Original line number Diff line number Diff line
;; -*- mode: lisp; indent-tabs-mode: nil; -*-
;;; -*- mode: lisp; indent-tabs-mode: nil; -*-

(defpackage :example
(defpackage :stomp-example
  (:use :cl
        :cl-user))

(in-package :example)
(in-package :stomp-example)


(defparameter *stomp* nil)
(defparameter *health-request* "/topic/health-request")
(defparameter *health-response* "/topic/health-response")
(defparameter *host* "localhost")
(defparameter *port* 61613)
(defparameter *host* "mjr")     ;or "localhost"
(defparameter *port* 61613)     ;by convention
(defparameter *counter* 0)

(defun out (fmt &rest arguments)
  (apply #'format *standard-output* fmt arguments)
  (finish-output *standard-output*)
  (force-output *standard-output*))
  (finish-output *standard-output*))

(defun callback (frame)
  (incf *counter*)
  (out "[~a]~%" (stomp:frame-body-of frame))
  (out "[~a]~%" (stomp:frame-body frame))
  (let ((msg (format nil "<pong><name>foo</name><count>~a</count></pong>" *counter*)))
    (stomp:post *stomp* msg *health-response*)))

(defun bark (frame)
  (let ((body (stomp:frame-body-of frame)))
  (let ((body (stomp:frame-body frame)))
    (out "--> bark : ~a~%" body)))

(defun chirp (frame)
  (let ((body (stomp:frame-body-of frame)))
  (let ((body (stomp:frame-body frame)))
    (out "--> chirp: ~a~%" body)))

(defun run ()
  (setf *stomp* (stomp:make-connection *host* *port*))
  (stomp:connect *stomp*)
  (stomp:register *stomp* #'callback *health-request*)
  (stomp:register *stomp* #'chirp *health-response*)
  (stomp:register *stomp* #'bark *health-response*)
  (stomp:start *stomp*))

(defun start ()
  (sb-thread:make-thread (lambda () (run)) :name "stomp-subscribe"))
  #+sbcl (sb-thread:make-thread (lambda () (run)) :name "stomp-subscribe")
  #+ccl  (ccl:process-run-function "stomp-subscribe" (lambda () (run))))

(defun stop ()
  (cl-stomp:stop *stomp*))
  (stomp:stop *stomp*)
  (setf *stomp* nil))