Skip to content

Commit

Permalink
enable publishing - so we can publish (on an interval - 2mins?) prices
Browse files Browse the repository at this point in the history
consider if all prices or only those asked for
  • Loading branch information
mpisanko committed Aug 26, 2024
1 parent ff27cb7 commit ac13293
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions reference-service/src/reference_service/web/socket.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@
(.disconnect ^Socket socket)
(reset! client {:connected? false}))))

(defn publish
[topic payload]
(let [{:keys [socket connected?]} @client]
(when (and socket
connected?)
(.emit ^Socket socket
"publish"
(to-array
[(json/write-value-as-string
{:topic (str "/" topic)
:payload payload
:type topic})])))))

(defn connect
[jdbc-ds uri]
(disconnect client)
Expand Down Expand Up @@ -79,3 +92,14 @@
[jdbc-ds uri]
(connect jdbc-ds uri)
client)

(comment
(def sock (connect nil "http://localhost:18086"))
(.emit ^Socket sock
"publish"
(to-array [(json/write-value-as-string
{:topic "/prices"
:payload {:ticker "AAPL"
:price 100}
:type "Price"})]))
#_1)

0 comments on commit ac13293

Please sign in to comment.