Tag Archives: Lisp

How to Receive a Message from an Apache ActiveMQ Topic with SISC

W/o Durability

(import s2j)

(define-java-class <javax.jms.session>)

(define-java-class <org.apache.activemq.active-m-q-connection-factory>)

(define connFactory (java-new <org.apache.activemq.active-m-q-connection-factory> ()))

(define createConnection (generic-java-method '|createConnection|))

(define conn (createConnection connFactory))

(define createSession (generic-java-method '|createSession|))

(define autoAcknowledge (generic-java-field-accessor '|AUTO_ACKNOWLEDGE|))

(define sess (createSession conn (->jboolean #f) (autoAcknowledge (java-null <javax.jms.session>))))

(define createTopic (generic-java-method '|createTopic|))

(define dest (createTopic sess (->jstring "SampleTopic")))

(define createConsumer (generic-java-method '|createConsumer|))

(define cons (createConsumer sess dest))

(define start (generic-java-method '|start|))

(start conn)

(define receive (generic-java-method '|receive|))

(define msg (receive cons))

(display msg)

(define close (generic-java-method '|close|)) 

(close conn)

W/ Durability

(import s2j)

(define-java-class <javax.jms.session>)

(define-java-class <org.apache.activemq.active-m-q-connection-factory>)

(define connFactory (java-new <org.apache.activemq.active-m-q-connection-factory>))

(define createConnection (generic-java-method '|createConnection|))

(define conn (createConnection connFactory))

(define setClientID (generic-java-method '|setClientID|))

(setClientID conn (->jstring "SampleClient"))

(define createSession (generic-java-method '|createSession|))

(define autoAcknowledge (generic-java-field-accessor '|AUTO_ACKNOWLEDGE|))

(define sess (createSession conn (->jboolean #f) (autoAcknowledge (java-null <javax.jms.session>))))

(define createTopic (generic-java-method '|createTopic|))

(define topic (createTopic sess (->jstring "SampleTopic")))

(define createDurableSubscriber (generic-java-method '|createDurableSubscriber|))

(define cons (createDurableSubscriber sess topic (->jstring "SampleSubscription")))

(define start (generic-java-method '|start|))

(start conn)

(define receive (generic-java-method '|receive|))

(define msg (receive cons))

(display msg)

(define close (generic-java-method '|close|)) 

(close conn)
Advertisements

How to Receive a Message from an Apache ActiveMQ Queue with SISC

(import s2j)

(define-java-class <javax.jms.session>)

(define-java-class <org.apache.activemq.active-m-q-connection-factory>)

(define connFactory (java-new <org.apache.activemq.active-m-q-connection-factory>))

(define createConnection (generic-java-method '|createConnection|))

(define conn (createConnection connFactory))

(define createSession (generic-java-method '|createSession|))

(define autoAcknowledge (generic-java-field-accessor '|AUTO_ACKNOWLEDGE|))

(define sess (createSession conn (->jboolean #f) (autoAcknowledge (java-null <javax.jms.session>))))

(define createQueue (generic-java-method '|createQueue|))

(define dest (createQueue sess (->jstring "SampleQueue")))

(define createConsumer (generic-java-method '|createConsumer|))

(define cons (createConsumer sess dest))

(define start (generic-java-method '|start|))

(start conn)

(define receive (generic-java-method '|receive|))

(define msg (receive cons))

(display msg)

(define close (generic-java-method '|close|)) 

(close conn)

How to Send a Message to an Apache ActiveMQ Topic with SISC

(import s2j)

(define-java-class <javax.jms.session>)

(define-java-class <org.apache.activemq.active-m-q-connection-factory>)

(define connFactory (java-new <org.apache.activemq.active-m-q-connection-factory>))

(define createConnection (generic-java-method '|createConnection|))

(define conn (createConnection connFactory))

(define createSession (generic-java-method '|createSession|))

(define autoAcknowledge (generic-java-field-accessor '|AUTO_ACKNOWLEDGE|))

(define sess (createSession conn (->jboolean #f) (autoAcknowledge (java-null <javax.jms.session>))))

(define createTopic (generic-java-method '|createTopic|))

(define dest (createTopic sess (->jstring "SampleTopic")))

(define createProducer (generic-java-method '|createProducer|))

(define prod (createProducer sess dest))

(define send (generic-java-method '|send|))

(define createTextMessage (generic-java-method '|createTextMessage|))

(define msg (createTextMessage sess (->jstring "Simples Assim")))

(send prod msg)

(define close (generic-java-method '|close|)) 

(close conn)

How to Send a Message to an Apache ActiveMQ Queue with SISC

(import s2j)

(define-java-class <javax.jms.session>)

(define-java-class <org.apache.activemq.active-m-q-connection-factory>)

(define connFactory (java-new <org.apache.activemq.active-m-q-connection-factory>))

(define createConnection (generic-java-method '|createConnection|))

(define conn (createConnection connFactory))

(define createSession (generic-java-method '|createSession|))

(define autoAcknowledge (generic-java-field-accessor '|AUTO_ACKNOWLEDGE|))

(define sess (createSession conn (->jboolean #f) (autoAcknowledge (java-null <javax.jms.session>))))

(define createQueue (generic-java-method '|createQueue|))

(define dest (createQueue sess (->jstring "SampleQueue")))

(define createProducer (generic-java-method '|createProducer|))

(define prod (createProducer sess dest))

(define send (generic-java-method '|send|))

(define createTextMessage (generic-java-method '|createTextMessage|))

(define msg (createTextMessage sess (->jstring "Simples Assim")))

(send prod msg)

(define close (generic-java-method '|close|)) 

(close conn)

How to Receive a Message from an Apache ActiveMQ Topic with Allegro CL

W/o Durability

(in-package :socket)

(let ((stream (make-socket :remote-host "localhost" :remote-port 61613)))
  (format stream "CONNECT~%~%~C" #\null)
 
  (force-output stream)

  ; Skip the CONNECT frame
  (loop for line = (read-line stream) until (string= line #\null))
 
  (format stream "SUBSCRIBE~%destination:/topic/SampleTopic~%ack:auto~%~%~C" #\null)
 
  (force-output stream)

  ; Seek to the body of the MESSAGE frame 
  (loop for line = (read-line stream) until (string= line ""))

  (print (read-line stream))
 
  (format stream "DISCONNECT~%~%~C" #\null)
)

W/ Durability

(in-package :socket)

(let ((stream (make-socket :remote-host "localhost" :remote-port 61613)))
  (format stream "CONNECT~%client-id:SampleClient~%~%~C" #\null)
 
  (force-output stream)

  ; Skip the CONNECT frame
  (loop for line = (read-line stream) until (string= line #\null))
 
  (format stream "SUBSCRIBE~%destination:/topic/SampleTopic~%ack:auto~%activemq.subscriptionName:SampleSubscription~%~%~C" #\null)
 
  (force-output stream)

  ; Seek to the body of the MESSAGE frame 
  (loop for line = (read-line stream) until (string= line ""))

  (print (read-line stream))
 
  (format stream "DISCONNECT~%~%~C" #\null)
)

How to Receive a Message from an Apache ActiveMQ Queue with Allegro CL

(in-package :socket)

(let ((stream (make-socket :remote-host "localhost" :remote-port 61613)))
  (format stream "CONNECT~%~%~C" #\null)
 
  (force-output stream)

  ; Skip the CONNECT frame
  (loop for line = (read-line stream) until (string= line #\null))
 
  (format stream "SUBSCRIBE~%destination:SampleQueue~%ack:auto~%~%~C" #\null)
 
  (force-output stream)

  ; Seek to the body of the MESSAGE frame 
  (loop for line = (read-line stream) until (string= line ""))

  (print (read-line stream))
 
  (format stream "DISCONNECT~%~%~C" #\null)
)

How to Receive a Message from an Apache ActiveMQ Topic with Bigloo

W/o Durability

(define socket (make-client-socket "localhost" 61613))

(define in (socket-input socket))

(define out (socket-output socket))

(fprintf out "CONNECT~%~%~a" #\null)

(flush-output-port out)

(let loop ((line (read-line in))) (cond ((not (string=? line (string #\null))) (loop (read-line in)))))

(fprintf out "SUBSCRIBE~%destination:/topic/SampleTopic~%~%ack:auto~%~%~a" #\null)

(flush-output-port out)

(let loop ((line (read-line in))) (cond ((not (string=? line "")) (loop (read-line in)))))

(display (read-line in))

(fprintf out "DISCONNECT~%~%~a" #\null)

(socket-close socket)

(socket-shutdown socket)

W/ Durability

(define socket (make-client-socket "localhost" 61613))

(define in (socket-input socket))

(define out (socket-output socket))

(fprintf out "CONNECT~%client-id:SampleClient~%~%~a" #\null)

(flush-output-port out)

(let loop ((line (read-line in))) (cond ((not (string=? line (string #\null))) (loop (read-line in)))))

(fprintf out "SUBSCRIBE~%destination:/topic/SampleTopic~%ack:auto~%activemq.subscriptionName:SampleSubscription~%~%~a" #\null)

(flush-output-port out)

(let loop ((line (read-line in))) (cond ((not (string=? line "")) (loop (read-line in)))))

(display (read-line in))

(fprintf out "DISCONNECT~%~%~a" #\null)

(socket-close socket)

How to Receive a Message from an Apache ActiveMQ Queue with Bigloo

(define socket (make-client-socket "localhost" 61613))

(define in (socket-input socket))

(define out (socket-output socket))

(fprintf out "CONNECT~%~%~a" #\null)

(flush-output-port out)

(let loop ((line (read-line in))) (cond ((not (string=? line (string #\null))) (loop (read-line in)))))

(fprintf out "SUBSCRIBE~%destination:SampleQueue~%~%ack:auto~%~%~a" #\null)

(flush-output-port out)

(let loop ((line (read-line in))) (cond ((not (string=? line "")) (loop (read-line in)))))

(display (read-line in))

(fprintf out "DISCONNECT~%~%~a" #\null)

(socket-close socket)