-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
22 additions
and
10 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
(ns ketu.decorators.consumer.decorator | ||
(:require [ketu.decorators.consumer.protocol :as cdp])) | ||
|
||
(defn- validate [consumer-decorator consumer-opts] | ||
(when (not (cdp/validate consumer-decorator consumer-opts)) | ||
(defn- valid? [consumer-decorator consumer-opts] | ||
(when (not (cdp/valid? consumer-decorator consumer-opts)) | ||
(throw (Exception. "Consumer decorator validation failed")))) | ||
|
||
(defn decorate-poll-fn | ||
[consumer-ctx poll-fn {:keys [ketu.source/consumer-decorator] :as consumer-opts}] | ||
(validate consumer-decorator consumer-opts) | ||
(valid? consumer-decorator consumer-opts) | ||
#(cdp/poll! consumer-decorator consumer-ctx poll-fn)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
(ns ketu.decorators.consumer.protocol) | ||
|
||
(defprotocol ConsumerDecorator | ||
(poll! [this consumer-ctx poll-fn] "fn [consumer-context poll-fn] -> Iterable<ConsumerRecord>") | ||
(validate [this consumer-opts] "Returns true if consumer-opts are valid according to the decorator logic")) | ||
"Consumer decorator provides a way to extend the consumer source functionality. | ||
The decorator runs in the context of the polling thread and allows custom control on the internal consumer instance" | ||
(poll! [this consumer-ctx poll-fn] | ||
"Decorates the internal consumer poll loop. | ||
- Parameters: | ||
- `consumer-ctx`: A map containing the consumer context, typically {:ketu.source/consumer consumer}. | ||
- `poll-fn`: A function with no arguments that returns an Iterable of ConsumerRecord. | ||
- Returns: An iterable collection of ConsumerRecord. | ||
- The decorator should call the `poll-fn` on behalf of the consumer source.") | ||
(valid? [this consumer-opts] | ||
"Validates the consumer options according to the decorator logic. | ||
- Parameters: | ||
- `consumer-opts`: A map of consumer options to be validated. | ||
- Returns: true if the consumer options are valid according to the decorator logic, false otherwise.")) |