I have installed a RabbitMQ server for Liitin project (http://liitin.org)
to develop and test various messaging possibilities between users and
various devices and services (Internet of Things). So far I have a very
small toy program to publish and subscribe to dummy notifications.

Now I'd like to modify the code for cases when needing to make more direct
enquiries or remote controls with a feedback.

Here is what I have so far. Anybody is free to test it until I change the
password :)


;XXXXXXXX SUB XXXXXXXXXX
;;; Have this running in one DrRacket tab, before running the PUB in
another tab.
;;; Then switch back to SUB to see the incoming notifications

#lang racket

(require (planet "main.rkt" ("tonyg" "stomp.plt" 3 2)))
(require mzlib/string)

;;; DEVICE SUBSCRIPTION

(define (my-message-handler message)
  (define disarmed-message (read-from-string (bytes->string/utf-8
(stomp-frame-body message))))
  (define signer "unknown"); extract from signed (open-air) message
  (define timestamp "unknown"); extract when the package was wrapped
  (define interpreter car)
  (define arguments cdr)
  (when (list? disarmed-message); ignore others
    (begin (display "  You received a new message signed by '") (display
signer)(display "' dated '")(display timestamp)(display "': ")(print
disarmed-message)(newline); Add "signed by..."
           (cond
             ((equal? 'store-photo (interpreter disarmed-message)) (thread
(lambda () (display "    This places a new photo to your
photo album")(newline)(newline)))); "(eval
disarmed-message))))); Eval reguires Liitin environment
             ((equal? 'pull-request (interpreter disarmed-message))
(thread (lambda () (display "    This is a
pull-request")(newline)(newline)))); "(eval
disarmed-message))))); Eval reguires Liitin environment
             ((equal? 'instant-notification (interpreter
disarmed-message)) (thread (lambda () (display "    This is
an instant notification")(newline)(newline)))); "(eval
disarmed-message))))); Eval reguires Liitin environment
             ((equal? 'device-settings (interpreter disarmed-message))
(thread (lambda () (display "    These are the current
settings for the specified device")(newline)(newline))));
"(eval disarmed-message))))); Eval reguires Liitin
environment
             ))))


(define (listen-to-my-messages)
  (define credientials (stomp-connect "liitin.org" #:login "device7"
#:passcode "Guest313" #:virtual-host "/")); #:headers, #:login,
#:passcode, #:port-number, #:request-versions, and #:virtual-host
  (stomp-subscribe credientials "/queue/device7.default" "my-subscription"
#:ack-mode 'auto #:headers '((persistent "true"))); verify format! Also,
prohibit listening others!
  (thread (lambda ()
            (let loop ()
              (let ((open-air-message (stomp-next-message credientials
"my-subscription"))); I.e, this is seen outside world, so
secure it!
                (my-message-handler open-air-message); filters out
anything else
                (loop)))))
  (display "Listening new messages...")(newline)(newline))


(listen-to-my-messages)


;XXXXXXXX PUB XXXXXXXXXX

#lang racket


(require (planet "main.rkt" ("tonyg" "stomp.plt" 3 2)))

;;; PUBLICATION


(define credientials (stomp-connect "liitin.org" #:login "device7"
#:passcode "Guest313" #:virtual-host "/"))

(define (default-address recipient)
  (string-append "/queue/" recipient ".default"))

(define (my-encrypt-signer data)
  data); place-holder only for now!

(define (wrap sender recipient-list encrypt-signer data)
  (list sender (current-seconds) recipient-list (encrypt-signer data)))


(define (send-default-message recipient secured-message)
  (call-with-receipt credientials
                     (lambda (receipt)
                       (stomp-send credientials (default-address
recipient) (string->bytes/utf-8 secured-message)
#:headers `((receipt ,receipt)(persistent
"true")))))); verify format!
                       ;(stomp-send credientials (default-address
recipient) (string->bytes/utf-8 secured-message)
#:headers `((receipt ,receipt)(persistent
"true")(reply-to "/temp-queue/foo")))))); verify
format!

;; TESTING

(define secured-message1 "(store-photo photo from-device7)"); place-holder
only for now. Sign and encrypt before placing open air.
(define secured-message2 "(pull-request target-object replacement-object
description from-device7)"); place-holder only for now. Sign and encrypt
also before placing open air.
(define secured-message3 "(instant-notification notification-content
from-device7)"); place-holder only for now. Sign and encrypt also before
placing open air.
(define secured-message4 "(device-settings device-x from-device7)");
place-holder only for now. Sign and encrypt also before placing open air.


(sleep 3)
(send-default-message "device7" secured-message1);This goes open air - be
sure to secure the message before sending it!
(sleep 5)
(send-default-message "device7" secured-message2)
(sleep 5)


(stomp-disconnect credientials)

;XX END XX


br, jukka


> On 08/06/2015 02:03 PM, Jukka Tuominen wrote:
>> From a generic STOMP documentation I’ve understood that I should send a
>> ”reply-to” header item with a temporary queue value, but I’m not sure
>> about the format I should use in racket-stomp. I tried...
>> #:headers `((receipt ,receipt)(persistent "true")(reply-to
>> "/temp-queue/foo"))
>> ... which returned  ”Received ERROR” without further information.
>
> You need to catch the `exn:stomp` exception, which includes the error
> frame; untested example code:
>
>   (with-handlers [(exn:stomp? (lambda (e)
>                                  (log-error "STOMP error ~v"
>                                             (exn:stomp-frame e))))]
>     ...)
>
> Also, it is a good idea to check the logs of whichever broker you are
> using.
>
>> Also, even though the target computer is able to receive the message,
>> I’m
>> not sure how to make it to respond with a value.
>
> Which broker are you using?
>
> Cheers,
>   Tony
>


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to