Skip to content
example.lisp 1.39 KiB
Newer Older
;;; -*- mode: lisp; indent-tabs-mode: nil; -*-
keith.irwin's avatar
keith.irwin committed

keith.irwin's avatar
keith.irwin committed
  (:use :cl
keith.irwin's avatar
keith.irwin committed


(defparameter *stomp* nil)
(defparameter *health-request* "/topic/health-request")
(defparameter *health-response* "/topic/health-response")
(defparameter *host* "mjr")     ;or "localhost"
(defparameter *port* 61613)     ;by convention
keith.irwin's avatar
keith.irwin committed
(defparameter *counter* 0)

(defun out (fmt &rest arguments)
  (apply #'format *standard-output* fmt arguments)
keith.irwin's avatar
keith.irwin committed

(defun callback (frame)
  (incf *counter*)
keith.irwin's avatar
keith.irwin committed
  (let ((msg (format nil "<pong><name>foo</name><count>~a</count></pong>" *counter*)))
    (stomp:post *stomp* msg *health-response*)))

(defun bark (frame)
keith.irwin's avatar
keith.irwin committed
    (out "--> bark : ~a~%" body)))

(defun chirp (frame)
keith.irwin's avatar
keith.irwin committed
    (out "--> chirp: ~a~%" body)))

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

(defun start ()
  #+sbcl (sb-thread:make-thread (lambda () (run)) :name "stomp-subscribe")
  #+ccl  (ccl:process-run-function "stomp-subscribe" (lambda () (run))))
keith.irwin's avatar
keith.irwin committed

(defun stop ()