Created
January 29, 2014 01:06
-
-
Save minostro/8679788 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns intl-mbus.core | |
(:import (javax.jms Connection MessageProducer Queue Session TextMessage) | |
(org.hornetq.api.core TransportConfiguration) | |
(java.util HashMap Map) | |
(org.hornetq.api.jms HornetQJMSClient JMSFactoryType) | |
(org.hornetq.jms.client HornetQConnectionFactory) | |
(org.hornetq.jms.client HornetQConnectionFactory)) | |
(:require [cheshire.core :refer :all])) | |
(def props (java.util.HashMap. {"host" "10.6.81.225" "port" (Integer. 10255)})) | |
(def transport-config (TransportConfiguration. "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" props)) | |
(def hq-factory (HornetQJMSClient/createConnectionFactoryWithoutHA JMSFactoryType/CF ^"[Lorg.hornetq.api.core.TransportConfiguration;" (into-array [transport-config]))) | |
(def queue (HornetQJMSClient/createQueue "VATInvoiceQueue")) | |
;(.setReconnectAttemps hq-factory -1) | |
(.setRetryInterval hq-factory 1000) | |
(.setConnectionTTL hq-factory 120000) | |
(.setClientFailureCheckPeriod hq-factory 2000) | |
(.setCallTimeout hq-factory 60000) | |
(.setConsumerWindowSize hq-factory 4194304) | |
(.setInitialConnectAttempts hq-factory -1) | |
(def connection (.createConnection hq-factory)) | |
(def session (.createSession connection false Session/CLIENT_ACKNOWLEDGE)) | |
(def producer (.createProducer session queue)) | |
(def ^:dynamic *current-connection* (atom false)) | |
(def ^:dynamic *current-session* (atom false)) | |
(def ^:dynamic *current-producer* (atom false)) | |
(defn start-connection | |
[] | |
(swap! *current-connection* (fn [_] (.createConnection hq-factory))) | |
(swap! *current-session* (fn [_] (.createSession connection false Session/CLIENT_ACKNOWLEDGE))) | |
(swap! *current-producer* (fn [_] (.createProducer session queue))) | |
(.start @*current-connection*)) | |
(defn close-connection | |
[] | |
(.close @*current-producer*) | |
(.close @*current-session*) | |
(.close @*current-connection*)) | |
(defn send-message | |
[msg] | |
(start-connection) | |
(let [msg (.createTextMessage session msg)] | |
(.setStringProperty msg "suppress_content_length" "true") | |
(.send @*current-producer* msg)) | |
(close-connection)) | |
(defn publish-json-message | |
"publish a message" | |
[msg] | |
(send-message (generate-string msg))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment