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

W/o Durability

(import "javax.jms.Session")
 
(import "org.apache.activemq.ActiveMQConnectionFactory")
 
(define connFactory (ActiveMQConnectionFactory.))
 
(define conn (.createConnection connFactory))
 
(define sess (.createSession conn #f Session.AUTO_ACKNOWLEDGE$))
 
(define dest (.createTopic sess "SampleTopic"))
 
(define consumer (.createConsumer sess dest))

(.start conn)
 
(define msg (.receive consumer))
 
(display msg)

(.close conn)

W/ Durability

(import "javax.jms.Session")
 
(import "org.apache.activemq.ActiveMQConnectionFactory")
 
(define connFactory (ActiveMQConnectionFactory.))
 
(define conn (.createConnection connFactory))
 
(.setClientID conn "SampleClient") 
 
(define sess (.createSession conn #f Session.AUTO_ACKNOWLEDGE$))
 
(define topic (.createTopic sess "SampleTopic"))
 
(define consumer (.createDurableSubscriber sess topic "SampleSubscription"))

(.start conn)
 
(define msg (.receive consumer))
 
(display msg)

(.close conn)

Published by:

Fernando Ribeiro

Experienced tech executive with a 24-year track record in enterprise computing. Leading AWS's professional services application modernization division in Brazil. He's held diverse roles including management, solutions architecture, sales consultancy, and full-stack development at major players like Oracle, Red Hat, and IBM. Fernando also contributes to open source and writes about emerging technologies. The views expressed here are his own and do not necessarily reflect the views of AWS.

Categories SoftwareTags , , , , , , , Leave a comment

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.