-
-
Save lsevero/f4d5570e2d61a61b441b9513a421a9f7 to your computer and use it in GitHub Desktop.
Revisions
-
mikeball revised this gist
Oct 21, 2015 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,9 @@ ; Postgres listen/notify in Clojure using http://impossibl.github.io/pgjdbc-ng/ ; in project.clj dependencies ; [com.impossibl.pgjdbc-ng/pgjdbc-ng "0.5"] (ns pglisten.core (:import [com.impossibl.postgres.jdbc PGDataSource] [com.impossibl.postgres.api.jdbc PGNotificationListener])) @@ -34,5 +38,10 @@ ; trigger message using psql, should print to console in clojure app. ; select pg_notify('mymessages', 'hello...'); -
mikeball created this gist
Oct 21, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ ; Postgres listen/notify in Clojure using http://impossibl.github.io/pgjdbc-ng/ (ns pglisten.core (:import [com.impossibl.postgres.jdbc PGDataSource] [com.impossibl.postgres.api.jdbc PGNotificationListener])) (def datasource (doto (PGDataSource.) (.setHost "localhost") ; todo move into (.setPort 5432) (.setDatabase "listenpg_db") (.setUser "listenpg_user") (.setPassword "password"))) ; create a listener that triggers when a message is received (def listener (reify PGNotificationListener (^void notification [this ^int processId ^String channelName ^String payload] (println "msg: " payload) ))) ; setup a connection with the listener (def connection (doto (.getConnection datasource) (.addNotificationListener listener))) ; begin listening to a channel (doto (.createStatement connection) (.execute "LISTEN mymessages;") (.close))