hw-kafka-client 1.1.2 → 1.1.3
raw patch · 5 files changed
+70/−22 lines, 5 files
Files
- README.md +13/−2
- hw-kafka-client.cabal +11/−1
- src/Kafka/Consumer/ConsumerProperties.hs +19/−0
- src/Kafka/Producer/ProducerProperties.hs +8/−0
- tests/Kafka/IntegrationSpec.hs +19/−19
README.md view
@@ -19,8 +19,19 @@ group the set of consumers attempt to "rebalance" the load to assign partitions to each consumer. ### Example:-A working consumer example can be found here: [ConsumerExample.hs](example/ConsumerExample.hs)+```+$ stack build --flag hw-kafka-client:examples+``` +or++```+$ stack build --exec kafka-client-example --flag hw-kafka-client:examples+```++A working consumer example can be found here: [ConsumerExample.hs](example/ConsumerExample.hs)</br>+To run an example please compile with the `examples` flag:+ ```Haskell import Data.Monoid ((<>)) import Kafka@@ -115,7 +126,7 @@ git clone https://github.com/edenhill/librdkafka cd librdkafka ./configure- make && sudo make install+ make && make install Sometimes it is helpful to specify openssl includes explicitly:
hw-kafka-client.cabal view
@@ -1,5 +1,5 @@ name: hw-kafka-client-version: 1.1.2+version: 1.1.3 homepage: https://github.com/haskell-works/hw-kafka-client bug-reports: https://github.com/haskell-works/hw-kafka-client/issues license: MIT@@ -23,6 +23,11 @@ extra-source-files: README.md +flag examples+ default: False+ manual: True+ description: Also compile examples+ source-repository head type: git location: git://github.com/haskell-works/hw-kafka-client.git@@ -41,6 +46,11 @@ , transformers , unix , hw-kafka-client++ if flag(examples)+ buildable: True+ else+ buildable: False library Build-tools: c2hs
src/Kafka/Consumer/ConsumerProperties.hs view
@@ -79,12 +79,26 @@ consumerCompression c = extraConsumerProps $ M.singleton "compression.codec" (kafkaCompressionCodecToString c) +-- | Suppresses consumer disconnects logs.+--+-- It might be useful to turn this off when interacting with brokers+-- with an aggressive connection.max.idle.ms value.+consumerSuppressDisconnectLogs :: ConsumerProperties+consumerSuppressDisconnectLogs =+ extraConsumerProps $ M.fromList [("log.connection.close", "false")]+ -- | Any configuration options that are supported by /librdkafka/. -- The full list can be found <https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md here> extraConsumerProps :: Map String String -> ConsumerProperties extraConsumerProps m = ConsumerProperties m Nothing Nothing Nothing {-# INLINE extraConsumerProps #-} +-- | Any configuration options that are supported by /librdkafka/.+-- The full list can be found <https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md here>+extraConsumerProp :: String -> String -> ConsumerProperties+extraConsumerProp k v = ConsumerProperties (M.singleton k v) Nothing Nothing Nothing+{-# INLINE extraConsumerProp #-}+ -- | Sets debug features for the consumer. -- Usually is used with 'consumerLogLevel'. consumerDebug :: [KafkaDebug] -> ConsumerProperties@@ -92,3 +106,8 @@ consumerDebug d = let points = L.intercalate "," (kafkaDebugToString <$> d) in extraConsumerProps $ M.fromList [("debug", points)]++consumerQueuedMaxMessagesKBytes :: Int -> ConsumerProperties+consumerQueuedMaxMessagesKBytes kBytes =+ extraConsumerProp "queued.max.messages.kbytes" (show kBytes)+{-# INLINE consumerQueuedMaxMessagesKBytes #-}
src/Kafka/Producer/ProducerProperties.hs view
@@ -42,6 +42,14 @@ extraProducerProps :: Map String String -> ProducerProperties extraProducerProps m = ProducerProperties m M.empty Nothing +-- | Suppresses producer disconnects logs.+--+-- It might be useful to turn this off when interacting with brokers+-- with an aggressive connection.max.idle.ms value.+producerSuppressDisconnectLogs :: ProducerProperties+producerSuppressDisconnectLogs =+ extraProducerProps $ M.fromList [("log.connection.close", "false")]+ -- | Any configuration options that are supported by /librdkafka/. -- The full list can be found <https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md here> extraProducerTopicProps :: Map String String -> ProducerProperties
tests/Kafka/IntegrationSpec.hs view
@@ -6,12 +6,12 @@ ) where import Control.Exception-import Control.Monad (forM_)+import Control.Monad (forM_) import Control.Monad.Loops-import Data.Monoid ((<>))+import qualified Data.ByteString as BS import Data.Either+import Data.Monoid ((<>)) import System.Environment-import qualified Data.ByteString as BS import Kafka @@ -37,23 +37,23 @@ spec :: Spec spec = describe "Kafka.IntegrationSpec" $ do- -- it "sends messages to test topic" $ do- -- broker <- brokerAddress- -- topic <- testTopic- -- let msgs = testMessages topic- -- res <- runProducer (producerProps broker) (sendMessages msgs)- -- res `shouldBe` Right ()- --- -- it "consumes messages from test topic" $ do- -- broker <- brokerAddress- -- topic <- testTopic- -- res <- runConsumer- -- (consumerProps broker)- -- (subscription topic)- -- receiveMessages- -- length <$> res `shouldBe` Right 2+ it "sends messages to test topic" $ do+ broker <- brokerAddress+ topic <- testTopic+ let msgs = testMessages topic+ res <- runProducer (producerProps broker) (sendMessages msgs)+ res `shouldBe` Right () - it "Integration spec is finished" $ 1 `shouldBe` 1+ it "consumes messages from test topic" $ do+ broker <- brokerAddress+ topic <- testTopic+ res <- runConsumer+ (consumerProps broker)+ (subscription topic)+ receiveMessages+ length <$> res `shouldBe` Right 2++ it "Integration spec is finished" $ True `shouldBe` True ----------------------------------------------------------------------------------------------------------------