Hoogle Search

Within LTS Haskell 24.67 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. module Kafka.Consumer

    Module to consume messages from Kafka topics. Here's an example of code to consume messages from a topic:

    import Control.Exception (bracket)
    import Control.Monad (replicateM_)
    import Kafka.Consumer
    
    -- Global consumer properties
    consumerProps :: ConsumerProperties
    consumerProps = brokersList ["localhost:9092"]
    <> groupId (ConsumerGroupId "consumer_example_group")
    <> noAutoCommit
    <> logLevel KafkaLogInfo
    
    -- Subscription to topics
    consumerSub :: Subscription
    consumerSub = topics [TopicName "kafka-client-example-topic"]
    <> offsetReset Earliest
    
    -- Running an example
    runConsumerExample :: IO ()
    runConsumerExample = do
    res <- bracket mkConsumer clConsumer runHandler
    print res
    where
    mkConsumer = newConsumer consumerProps consumerSub
    clConsumer (Left err) = pure (Left err)
    clConsumer (Right kc) = (maybe (Right ()) Left) <$> closeConsumer kc
    runHandler (Left err) = pure (Left err)
    runHandler (Right kc) = processMessages kc
    
    -- Example polling 10 times before stopping
    processMessages :: KafkaConsumer -> IO (Either KafkaError ())
    processMessages kafka = do
    replicateM_ 10 $ do
    msg <- pollMessage kafka (Timeout 1000)
    putStrLn $ "Message: " <> show msg
    err <- commitAllOffsets OffsetCommit kafka
    putStrLn $ "Offsets: " <> maybe "Committed." show err
    pure $ Right ()
    

  2. newtype ConsumerGroupId

    hw-kafka-client Kafka.Consumer

    Consumer group ID. Different consumers with the same consumer group ID will get assigned different partitions of each subscribed topic. See Kafka documentation on consumer group

  3. ConsumerGroupId :: Text -> ConsumerGroupId

    hw-kafka-client Kafka.Consumer

    No documentation available.

  4. data ConsumerRecord k v

    hw-kafka-client Kafka.Consumer

    Represents a received message from Kafka (i.e. used in a consumer)

  5. ConsumerRecord :: TopicName -> PartitionId -> Offset -> Timestamp -> Headers -> k -> v -> ConsumerRecord k v

    hw-kafka-client Kafka.Consumer

    No documentation available.

  6. data KafkaConsumer

    hw-kafka-client Kafka.Consumer

    The main type for Kafka consumption, used e.g. to poll and commit messages. Its constructor is intentionally not exposed, instead, one should use newConsumer to acquire such a value.

  7. closeConsumer :: MonadIO m => KafkaConsumer -> m (Maybe KafkaError)

    hw-kafka-client Kafka.Consumer

    Closes the consumer. See newConsumer

  8. newConsumer :: MonadIO m => ConsumerProperties -> Subscription -> m (Either KafkaError KafkaConsumer)

    hw-kafka-client Kafka.Consumer

    Create a KafkaConsumer. This consumer must be correctly released using closeConsumer.

  9. pollConsumerEvents :: KafkaConsumer -> Maybe Timeout -> IO ()

    hw-kafka-client Kafka.Consumer

    Polls the provided kafka consumer for events. Events will cause application provided callbacks to be called. The Timeout argument specifies the maximum amount of time (in milliseconds) that the call will block waiting for events. This function is called on each pollMessage and, if runtime allows multi threading, it is called periodically in a separate thread to ensure the callbacks are handled ASAP. There is no particular need to call this function manually unless some special cases in a single-threaded environment when polling for events on each pollMessage is not frequent enough.

  10. resumePartitions :: MonadIO m => KafkaConsumer -> [(TopicName, PartitionId)] -> m KafkaError

    hw-kafka-client Kafka.Consumer

    Resumes specified partitions on the current consumer.

Page 215 of many | Previous | Next