/
JmsController.clj
127 lines (114 loc) · 4.78 KB
/
JmsController.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
;;;
;;; Copyright 2016, Ruediger Gad
;;; Copyright 2014, 2015 University of Applied Sciences Frankfurt am Main
;;;
;;; This software is released under the terms of the Eclipse Public License
;;; (EPL) 1.0. You can find a copy of the EPL at:
;;; http://opensource.org/licenses/eclipse-1.0.php
;;;
(ns
^{:author "Ruediger Gad",
:doc "JMS controller for ActiveMQ."}
bowerick.JmsController
(:gen-class
:init init
:constructors {[Object] []}
:methods [^:static [configure [String] void]
^:static [createConsumer [String String bowerick.JmsConsumerCallback int] AutoCloseable]
^:static [createProducer [String String int] bowerick.JmsProducer]
^:static [createJsonConsumer [String String bowerick.JmsConsumerCallback int] AutoCloseable]
^:static [createJsonProducer [String String int] bowerick.JmsProducer]
^:static [createCarboniteConsumer [String String bowerick.JmsConsumerCallback int] AutoCloseable]
^:static [createCarboniteProducer [String String int] bowerick.JmsProducer]
^:static [createCarboniteLzfConsumer [String String bowerick.JmsConsumerCallback int] AutoCloseable]
^:static [createCarboniteLzfProducer [String String int] bowerick.JmsProducer]
[startEmbeddedBroker [] void]
[stopEmbeddedBroker [] void]]
:state state)
(:require
[bowerick.jms :as jms]
[cheshire.core :as cheshire]
[clj-assorted-utils.util :as utils])
(:import
(bowerick JmsConsumerCallback)))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -init [broker-url]
[[] {:broker-url broker-url :broker (ref nil)}])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -configure [config-file-path]
(let [cfg-file-data (if (utils/is-file? config-file-path)
(cheshire/parse-string (slurp config-file-path))
{})
jms-cfg (cfg-file-data "jms")]
(when (not (nil? jms-cfg))
(println "Applying jms configuration from config file:" config-file-path)
(doseq [[k v] jms-cfg]
(alter-var-root (ns-resolve 'bowerick.jms (symbol k)) (fn [_ x] x) v)))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -createConsumer [broker-url destination-description ^JmsConsumerCallback consumer-cb pool-size]
(jms/create-consumer
broker-url
destination-description
(fn [data msg-hdr]
(.processData consumer-cb data msg-hdr))
pool-size))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -createProducer [broker-url destination-description pool-size]
(jms/create-producer
broker-url
destination-description
pool-size))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -createJsonConsumer [broker-url destination-description ^JmsConsumerCallback consumer-cb pool-size]
(jms/create-json-consumer
broker-url
destination-description
(fn [data msg-hdr]
(.processData consumer-cb data msg-hdr))
pool-size))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -createJsonProducer [broker-url destination-description pool-size]
(jms/create-json-producer
broker-url
destination-description
pool-size))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -createCarboniteProducer [broker-url destination-description pool-size]
(jms/create-carbonite-producer
broker-url
destination-description
pool-size))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -createCarboniteConsumer [broker-url destination-description ^JmsConsumerCallback consumer-cb pool-size]
(jms/create-carbonite-consumer
broker-url
destination-description
(fn [data msg-hdr]
(.processData consumer-cb data msg-hdr))
pool-size))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -createCarboniteLzfProducer [broker-url destination-description pool-size]
(jms/create-carbonite-lzf-producer
broker-url
destination-description
pool-size))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -createCarboniteLzfConsumer [broker-url destination-description ^JmsConsumerCallback consumer-cb pool-size]
(jms/create-carbonite-lzf-consumer
broker-url
destination-description
(fn [data msg-hdr]
(.processData consumer-cb data msg-hdr))
pool-size))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -startEmbeddedBroker [this]
(let [broker-ref (:broker (.state this))]
(when (nil? @broker-ref)
(let [brkr (jms/start-broker (:broker-url (.state this)))]
(dosync (ref-set broker-ref brkr))))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn -stopEmbeddedBroker [this]
(let [broker-ref (:broker (.state this))]
(when (not (nil? @broker-ref))
(jms/stop @broker-ref)
(dosync (ref-set broker-ref nil)))))