13 , CommitOffsetsIfNecessary
24import Prelude (Unit, bind, (#), ($), (>>>))
25import Control.Promise (Promise, toAffE, fromAff)
26import Kafka.Kafka (Kafka)
27import Data.Function.Uncurried (Fn2, Fn3, Fn7, mkFn7, runFn2, runFn3)
29import Effect.Aff (Aff)
30import Data.Show (class Show)
32import Data.Nullable (Nullable, toMaybe)
33import Node.Buffer (Buffer)
34import Data.Maybe (Maybe, maybe)
35import Data.Traversable (traverse)
36import Control.Monad.Error.Class (throwError)
37import Effect.Exception (error)
38import Data.Int (fromString)
39import Control.Applicative (pure)
40import Data.Either (Either, either, note)
41import Data.Newtype (un, class Newtype)
43foreign import data Consumer :: Type
48instance ntGroupId :: Newtype GroupId String
50derive newtype instance showGroupId :: Show GroupId
53 = { groupId :: GroupId
54 , readUncommitted :: Boolean
55 , autoCommit :: Boolean
58type SubscriptionConfig
61foreign import makeConsumerImpl :: Fn2 Kafka ConsumerConfig Consumer
63makeConsumer :: Kafka -> ConsumerConfig -> Consumer
64makeConsumer = runFn2 makeConsumerImpl
66foreign import connectImpl :: Consumer -> Effect (Promise Unit)
68connect :: Consumer -> Aff Unit
69connect = connectImpl >>> toAffE
71foreign import subscribeImpl :: Fn2 Consumer SubscriptionConfig (Effect (Promise Unit))
73subscribe :: Consumer -> SubscriptionConfig -> Aff Unit
74subscribe consumer subscriptionConfig = runFn2 subscribeImpl consumer subscriptionConfig # toAffE
76type InternalConsumerMessage
77 = { key :: Nullable Buffer
82type InternalConsumerBatch
83 = { fetchedOffset :: String
84 , highWatermark :: String
85 , messages :: Array InternalConsumerMessage
91 = { key :: Maybe Buffer
97 = { fetchedOffset :: Offset
98 , highWatermark :: Offset
99 , messages :: Array ConsumerMessage
100 , partition :: Partition
104type InternalHeartbeat
105 = Effect (Promise Unit)
110type InternalResolveOffset
114 = Offset -> Effect Unit
116type InternalCommitOffsetsIfNecessary
117 = Effect (Promise Unit)
119type CommitOffsetsIfNecessary
122type InternalOffsetInfo
128 , partition :: String
134type InternalUncommittedOffsets
135 = Effect InternalOffsetInfo
143 , partition :: Partition
149raiseMaybe :: forall a. Maybe a -> Effect a
150raiseMaybe = maybe (throwError $ error "Maybe is Nothing") pure
152raiseEither :: forall a. Either String a -> Effect a
153raiseEither = either (error >>> throwError) pure
155toOffsetInfo :: InternalOffsetInfo -> Effect OffsetInfo
156toOffsetInfo { topics } = do
157 topicInfo <- traverse parseTopicInfo topics
158 pure { topics: topicInfo }
160 parsePartitionInfo ::
162 , partition :: String
166 , partition :: Partition
168 parsePartitionInfo { offset, partition } = do
169 o <- raiseMaybe $ fromString offset
170 p <- raiseMaybe $ fromString partition
171 pure { offset: Offset o, partition: Partition p }
177 , partition :: String
185 , partition :: Partition
189 parseTopicInfo { partitions, topic } = do
190 partitionInfo <- traverse parsePartitionInfo partitions
191 pure { partitions: partitionInfo, topic: Topic topic }
193type UncommittedOffsets
202type InternalIsRunning
210 InternalConsumerBatch
211 InternalResolveOffset
213 InternalCommitOffsetsIfNecessary
214 InternalUncommittedOffsets
217 (Effect (Promise Unit))
223 CommitOffsetsIfNecessary ->
224 UncommittedOffsets ->
229toConsumerMessage :: InternalConsumerMessage -> Either String ConsumerMessage
230toConsumerMessage { key, value, offset } = do
231 o <- note "offset is not a number" $ fromString offset
238toConsumerBatch :: InternalConsumerBatch -> Either String ConsumerBatch
239toConsumerBatch { fetchedOffset, highWatermark, messages, partition, topic } = do
240 fo <- note "fetchedOffset is not a number" $ fromString fetchedOffset
241 hwm <- note "highWatermark is not a number" $ fromString highWatermark
242 msgs <- traverse toConsumerMessage messages
244 { fetchedOffset: Offset fo
245 , highWatermark: Offset hwm
247 , partition: Partition partition
251foreign import eachBatchImpl :: Fn3 Consumer Boolean EachBatchImpl (Effect (Promise Unit))
253eachBatch :: Consumer -> Boolean -> EachBatch -> Aff Unit
254eachBatch consumer eachBatchAutoResolve handler =
256 iResolveOffset :: (Int -> Effect Unit) -> (Offset -> Effect Unit)
257 iResolveOffset f = un Offset >>> f
259 iUncommitedOffsets :: Effect InternalOffsetInfo -> Effect OffsetInfo
260 iUncommitedOffsets ioiEff = do
264 internalHandlerCurried ::
265 InternalConsumerBatch ->
266 InternalResolveOffset ->
268 InternalCommitOffsetsIfNecessary ->
269 InternalUncommittedOffsets ->
272 (Effect (Promise Unit))
273 internalHandlerCurried icb iro ih icoin iuo iir iis = do
274 batch <- raiseEither (toConsumerBatch icb)
280 (iUncommitedOffsets iuo)
285 internalHandler :: EachBatchImpl
286 internalHandler = mkFn7 internalHandlerCurried
288 runFn3 eachBatchImpl consumer eachBatchAutoResolve internalHandler # toAffE
290foreign import disconnectImpl :: Consumer -> Effect (Promise Unit)
292disconnect :: Consumer -> Aff Unit
293disconnect = disconnectImpl >>> toAffE
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list