Professional Documents
Culture Documents
Getting Started With JMS in Clojure - Clojure Recipes
Getting Started With JMS in Clojure - Clojure Recipes
PREV NEXT
⏮ ⏭
20. Getting Started with Storm 22. Integrating Storm and JMS
🔎
In this recipe we’ll create a new Clojure project and create a JMS queue
using a Hornet library. Then we’ll pump messages onto the queue and see
them appear in our output.
ASSUMPTIONS
In this chapter we assume that either you’re familiar with the concept of a
JMS message or you are at least willing to look it up.
BENEFITS
The benefit of this chapter is being able to integrate with existing JMS
messaging infrastructure as a producer or a consumer. It is also relevant
to real-time flows of information in Storm.
THE RECIPE—CODE
Follow these steps:
cd news-jms
[org.hornetq/hornetq-core "2.2
[org.hornetq/hornetq-jms "2.2.
[org.jboss.netty/netty "3.2.0.B
[org.jboss.javaee/jboss-jms-ap
⬆
:main news-jms.core)
Find answers on the fly, or master something new. Subscribe today. See pricing options. /
3. Next, modify the file src/news_jms/core.clj to include the
following:
(ns news-jms.core
(:gen-class)
(org.hornetq.api.core TransportConfigurat
(org.hornetq.core.remoting.impl.netty Net
NettyConnectorFactory)
(org.hornetq.jms.server.config.impl JMSCo
ConnectionFactoryConfigurationImpl JMSQueueConfigurat
(org.hornetq.jms.server.embedded Embedded
(java.util ArrayList)))
(defn get-server
NettyConnectorFactory))
jmsConfig (JMSConfigurationImpl.)
connectorNames (ArrayList.)
(into-array '("/queue/queue1")))
jmsServer (EmbeddedJMS.)]
(doto configuration
(.setPersistenceEnabled false)
(.setSecurityEnabled false))
connectorConfig)
Find answers on the fly, or master something new. Subscribe today. See pricing options. /
(.add (.getConnectionFactoryConfigurations jmsCo
^ConnectionFactoryConfiguration cfConfig))
(doto jmsServer
(.setConfiguration configuration)
(.setJmsConfiguration jmsConfig)
(.start))
jmsServer))
(.stop server))
(sender/send-messages server)
(receiver/receive-messages server)
(stop-server server))
(println "done"))
(ns news-jms.send-messages
(java.util Date)))
(defn send-messages
[jmsServer]
(Date.)))]
Find answers on the fly, or master something new. Subscribe today. See pricing options.
(println "sent messages"))
/
5. Now create the file src/news_jms/receive_messages.clj with the
following contents:
(ns news-jms.receive-messages
(javax.jms Session)))
(defn receive-messages
[jmsServer]
(.start connection)
(.close connection))
lein run
You should see output similar to the following (along with other noise):
sent messages
CONCLUSION
We’ve gotten started with JMS in Clojure. We’ve started up an embedded
JMS server, sent a message, and received that message. We’ve got the
building blocks to put together a high availability solution.
Find answers on the fly, or master something new. Subscribe today. See pricing options. /