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

package ActiveMQSample where

data ActiveMQConnectionFactory = native org.apache.activemq.ActiveMQConnectionFactory where
  native createConnection :: Mutable s ActiveMQConnectionFactory -> STMutable s Connection throws JMSException
  native new :: () -> STMutable s ActiveMQConnectionFactory

data Connection = native javax.jms.Connection where
  native close :: Mutable s Connection -> ST s () throws JMSException
  native createSession :: Mutable s Connection -> Bool -> Int -> STMutable s Session throws JMSException

data Destination = pure native javax.jms.Destination

data JMSException = pure native javax.jms.JMSException

derive Exceptional JMSException
data Message = pure native javax.jms.Message

data MessageProducer = native javax.jms.MessageProducer where
  native send :: Mutable s MessageProducer -> Message -> ST s () throws JMSException

data Queue = pure native javax.jms.Queue

data Session = native javax.jms.Session where
  native autoAcknowledge javax.jms.Session.AUTO_ACKNOWLEDGE :: Int
  native createProducer :: Mutable s Session -> Destination -> STMutable s MessageProducer throws JMSException
  native createQueue :: Mutable s Session -> String -> ST s Queue throws JMSException
  native createTextMessage :: Mutable s Session -> String -> ST s TextMessage throws JMSException

data TextMessage = pure native javax.jms.TextMessage

main _ = do
  connFactory <- ActiveMQConnectionFactory.new ()

  conn <- connFactory.createConnection

  sess <- conn.createSession false Session.autoAcknowledge

  dest <- sess.createQueue "SampleQueue"

  prod <- sess.createProducer dest

  msg <- sess.createTextMessage "Simples Assim"

  prod.send msg

  conn.close

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.