Newer
Older
Francois-Rene Rideau
committed
;;; -*- mode: lisp; indent-tabs-mode: nil; -*-
Francois-Rene Rideau
committed
(defpackage :stomp-example
Francois-Rene Rideau
committed
:cl-user))
(in-package :stomp-example)
(defparameter *stomp* nil)
(defparameter *health-request* "/topic/health-request")
(defparameter *health-response* "/topic/health-response")
Francois-Rene Rideau
committed
(defparameter *host* "mjr") ;or "localhost"
(defparameter *port* 61613) ;by convention
(defparameter *counter* 0)
(defun out (fmt &rest arguments)
(apply #'format *standard-output* fmt arguments)
Francois-Rene Rideau
committed
(finish-output *standard-output*))
Francois-Rene Rideau
committed
(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)
Francois-Rene Rideau
committed
(let ((body (stomp:frame-body frame)))
Francois-Rene Rideau
committed
(let ((body (stomp:frame-body frame)))
(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 ()
Francois-Rene Rideau
committed
#+sbcl (sb-thread:make-thread (lambda () (run)) :name "stomp-subscribe")
#+ccl (ccl:process-run-function "stomp-subscribe" (lambda () (run))))
Francois-Rene Rideau
committed
(stomp:stop *stomp*)
(setf *stomp* nil))