-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kafka): naive consumer group (#1629)
- Loading branch information
Showing
13 changed files
with
980 additions
and
115 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module HStream.Kafka.Common.KafkaException | ||
( ErrorCodeException (..) | ||
) where | ||
|
||
import qualified Control.Exception as E | ||
import qualified Kafka.Protocol.Error as K | ||
|
||
------------------------------------------------------------------------------- | ||
|
||
newtype ErrorCodeException = ErrorCodeException K.ErrorCode deriving Show | ||
instance E.Exception ErrorCodeException |
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,45 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
|
||
module HStream.Kafka.Common.Utils where | ||
|
||
import Control.Exception (throw) | ||
import qualified Control.Monad as M | ||
import qualified Data.HashTable.IO as H | ||
import Data.Maybe (fromMaybe) | ||
import qualified Data.Vector as V | ||
import HStream.Kafka.Common.KafkaException (ErrorCodeException (ErrorCodeException)) | ||
import qualified Kafka.Protocol.Encoding as K | ||
|
||
type HashTable k v = H.BasicHashTable k v | ||
|
||
hashtableGet hashTable key errorCode = H.lookup hashTable key >>= \case | ||
Nothing -> throw (ErrorCodeException errorCode) | ||
Just v -> return v | ||
|
||
hashtableDeleteAll hashTable = do | ||
lst <- H.toList hashTable | ||
M.forM_ lst $ \(key, _) -> H.delete hashTable key | ||
|
||
kaArrayToList :: K.KaArray a -> [a] | ||
kaArrayToList = undefined | ||
|
||
listToKaArray :: [a] -> K.KaArray a | ||
listToKaArray = undefined | ||
|
||
kaArrayToVector :: K.KaArray a -> V.Vector a | ||
kaArrayToVector kaArray = fromMaybe V.empty (K.unKaArray kaArray) | ||
|
||
vectorToKaArray :: V.Vector a -> K.KaArray a | ||
vectorToKaArray vec = K.KaArray (Just vec) | ||
|
||
mapKaArray :: (a -> b) -> K.KaArray a -> K.KaArray b | ||
mapKaArray f arr = K.KaArray (fmap (V.map f) (K.unKaArray arr)) | ||
|
||
mapKaArrayM :: (a -> IO b) -> K.KaArray a -> IO (K.KaArray b) | ||
mapKaArrayM f arr = case K.unKaArray arr of | ||
Nothing -> return (K.KaArray Nothing) | ||
Just vec -> K.KaArray . Just <$> V.mapM f vec | ||
|
||
forKaArrayM :: K.KaArray a -> (a -> IO b) -> IO (K.KaArray b) | ||
forKaArrayM = flip mapKaArrayM |
Oops, something went wrong.