-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Word Count Modernization #191
Conversation
0e1e6e1
to
132c60f
Compare
132c60f
to
808ac80
Compare
(is (= 1 (word-count journal "understand"))) | ||
(is (= 2 (word-count journal "i"))) | ||
(is (= 3 (word-count journal "to")))))))) | ||
;; (ns word-count-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented out this namespace while development. I plan to put this back.
Codecov Report
@@ Coverage Diff @@
## master #191 +/- ##
==========================================
- Coverage 81.43% 78.74% -2.69%
==========================================
Files 40 41 +1
Lines 2391 2498 +107
Branches 149 149
==========================================
+ Hits 1947 1967 +20
- Misses 295 382 +87
Partials 149 149
Continue to review full report at Codecov.
|
examples/word-count/dev/user.clj
Outdated
{:topic-name (name key) | ||
:partition-count 1 | ||
:replication-factor 1 | ||
:key-serde (js/edn-serde) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should use a string serde for the key to make it easier to join with other topics. See https://github.com/FundingCircle/jackdaw-repl/commit/1ddd902e3ec325c862bdb2ef06f01050255b665e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind this is just for prototyping. We shouldn't use this or EDN keys in production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking we could add a new arity that takes an argument so the user can set their own default. Would that address your use case?
examples/word-count/dev/user.clj
Outdated
(str/join "|")) | ||
")"))))) | ||
|
||
(defmethod ig/halt-key! :app [_ {:keys [streams-config streams-app]}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started with that, and then separated out the cleanup or resources because sometimes you just want to stop the app but not delete everything so you can inspect the topics and state stores. https://github.com/FundingCircle/jackdaw-repl/commit/0ba5f6f70ab2a08f8f4d11819c5540d3e093574c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like you'd want a full reset to be able to start clean. Could we halt just the app with a different config structure?
examples/word-count/dev/user.clj
Outdated
(assoc [this key val] | ||
this)) | ||
|
||
(defn new-fake-topic-metadata [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just use a single instance of FakeTopicMetadata
, so we can drop this function and update topic-metadata
to be:
(def topic-metadata (FakeTopicMetadata.))
Then we can just use topic-metadata
where new-fake-topic-metadata
is currently used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do. Does this still make sense if we add an arity to allow the user to set their own default?
examples/word-count/dev/user.clj
Outdated
|
||
|
||
(defmethod ig/init-key :streams-config [_ streams-config] | ||
(let [bootstrap-servers (or (System/getenv "BOOTSTRAP_SERVERS") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this logic to where the config map is instantiated, and get rid of this init-key
method
src/jackdaw/repl.clj
Outdated
(let [client-config (assoc consumer-config | ||
"group.id" | ||
(str (java.util.UUID/randomUUID)))] | ||
(with-open [client (jc/subscribed-consumer client-config [topic-config])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using this function from the repl, I've always needed to call seek-to-beginning-eager
on the consumer before using it to consume messages. This may just be my setup though 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This config sets a random UUID for the consumer group. It will always start from the beginning. If we were to stop doing that, I think we would need to do as you suggest. I'm not sure which is preferable.
;; Evaluate the form: | ||
(let [text-input (slurp (io/resource "metamorphosis.txt")) | ||
values (str/split text-input #"\n")] | ||
(doseq [v values] | ||
(publish (:input topic-metadata) nil v) | ||
(info v)) | ||
(info "The End")) | ||
(println v)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice not to print every line, but some other (smaller) progress indicator. I use a fast terminal and it took a while - in an emacs buffer I imagine its a bit painful ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice - works for me with the tweak for clj -A:dev
in the CLI based instructions.
This PR updates the "Word Count" example.
Highlights:
dev
alias.When writing code, you can treat the topic metadata fake just like a map. When used with a "getter", it returns the topic metadata for the name supplied, EDN serdes for the key and value, and a partition count of one.
When in development, the topics are inferred from the topology. The dev workflow is largely unchanged. Simply jack in and type:
The
user
namespace is part of the dev alias and is not loaded automatically. To apply the dev alias, add the following to your Emacs config:or type
C-u -A:server:client:dev
when jacking in.