-
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.
* Consumer decorator protocol
- Loading branch information
Showing
8 changed files
with
110 additions
and
56 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
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(ns ketu.decorators.consumer.decorator | ||
(:require [ketu.decorators.consumer.protocol :as cdp])) | ||
|
||
(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}] | ||
(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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(ns ketu.decorators.consumer.protocol) | ||
|
||
(defprotocol ConsumerDecorator | ||
"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.")) |
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