Created
April 30, 2016 21:24
-
-
Save tolitius/a5fe7dfab29be1402bd2f560a64e6900 to your computer and use it in GitHub Desktop.
mount: accessing states within jars
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
;; [tolitius:/tmp/ido]$ cat src/ido/core.clj | |
(ns ido.core | |
(:require [mount.core :refer [defstate]])) | |
(defstate kafka :start 42 | |
:stop 0) | |
;; [tolitius:/tmp/ido]$ | |
;; [tolitius:/tmp/ido]$ lein install | |
;; Created /private/tmp/ido/target/ido-0.1.0-SNAPSHOT.jar | |
;; Wrote /private/tmp/ido/pom.xml | |
;; Installed jar and pom into local repo. | |
;; ^^^ separate JAR / project |
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
;; [tolitius:/tmp/micro-ido]$ cat project.clj | |
(defproject micro-ido "0.1.0-SNAPSHOT" | |
:description "FIXME: write description" | |
:url "http://example.com/FIXME" | |
:license {:name "Eclipse Public License" | |
:url "http://www.eclipse.org/legal/epl-v10.html"} | |
:dependencies [[org.clojure/clojure "1.8.0"] | |
[mount "0.1.11-SNAPSHOT"] | |
[ido "0.1.0-SNAPSHOT"]]) ;; << depending on the "ido" jar we just created above | |
;; [tolitius:/tmp/micro-ido]$ cat src/micro_ido/core.clj | |
(ns micro-ido.core | |
(:require [mount.core :refer [defstate]] | |
[ido.core :refer [kafka]])) | |
(defn with-kafka [kafka-dep] | |
(println "the ultimate kafka topic always has" kafka-dep "messages")) | |
(defstate micro-service :start (with-kafka kafka)) |
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
;; [tolitius:/tmp/micro-ido]$ lein repl | |
;; nREPL server started on port 64400 on host 127.0.0.1 - nrepl://127.0.0.1:64400 | |
user=> (require '[mount.core :as mount]) | |
;; mount hasn't seen any states yet | |
user=> (mount/start) | |
{:started []} | |
;; now let's require the micro service | |
user=> (require '[micro-ido.core]) | |
"|| mounting... #'ido.core/kafka" | |
"|| mounting... #'micro-ido.core/micro-service" | |
nil | |
;; ^^^ ok, so mound saw both, because micro-service _requires_ kafka, hence compiler saw it | |
;; let's kick it off | |
user=> (mount/start) | |
the ultimate kafka topic always has 42 messages | |
{:started ["#'ido.core/kafka" "#'micro-ido.core/micro-service"]} | |
;; great success :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment