1
1
{-# LANGUAGE OverloadedStrings #-}
2
2
3
+ -----------------------------------------------------------------------------
4
+ -- |
5
+ -- Module with consumer properties types and functions.
6
+ -----------------------------------------------------------------------------
3
7
module Kafka.Consumer.ConsumerProperties
4
8
( ConsumerProperties (.. )
5
9
, CallbackPollMode (.. )
@@ -34,9 +38,17 @@ import Kafka.Types (BrokerAddress (..), ClientId (..), KafkaC
34
38
35
39
import Kafka.Consumer.Callbacks as X
36
40
37
- data CallbackPollMode = CallbackPollModeSync | CallbackPollModeAsync deriving (Show , Eq )
38
-
39
- -- | Properties to create 'KafkaConsumer'.
41
+ -- | Whether the callback polling should be done synchronously or not.
42
+ data CallbackPollMode =
43
+ -- | You have to poll the consumer frequently to handle new messages
44
+ -- as well as rebalance and keep alive events.
45
+ -- This enables lowering the footprint and having full control over when polling
46
+ -- happens, at the cost of manually managing those events.
47
+ CallbackPollModeSync
48
+ -- | Handle polling rebalance and keep alive events for you in a background thread.
49
+ | CallbackPollModeAsync deriving (Show , Eq )
50
+
51
+ -- | Properties to create 'Kafka.Consumer.Types.KafkaConsumer'.
40
52
data ConsumerProperties = ConsumerProperties
41
53
{ cpProps :: Map Text Text
42
54
, cpLogLevel :: Maybe KafkaLogLevel
@@ -61,93 +73,96 @@ instance Monoid ConsumerProperties where
61
73
mappend = (Sem. <>)
62
74
{-# INLINE mappend #-}
63
75
76
+ -- | Set the <https://kafka.apache.org/documentation/#bootstrap.servers list of brokers> to contact to connect to the Kafka cluster.
64
77
brokersList :: [BrokerAddress ] -> ConsumerProperties
65
78
brokersList bs =
66
79
let bs' = Text. intercalate " ," ((\ (BrokerAddress x) -> x) <$> bs)
67
80
in extraProps $ M. fromList [(" bootstrap.servers" , bs')]
68
81
82
+ -- | Set the <https://kafka.apache.org/documentation/#auto.commit.interval.ms auto commit interval> and enables <https://kafka.apache.org/documentation/#enable.auto.commit auto commit>.
69
83
autoCommit :: Millis -> ConsumerProperties
70
84
autoCommit (Millis ms) = extraProps $
71
85
M. fromList
72
86
[ (" enable.auto.commit" , " true" )
73
87
, (" auto.commit.interval.ms" , Text. pack $ show ms)
74
88
]
75
89
76
- -- | Disables auto commit for the consumer
90
+ -- | Disable <https://kafka.apache.org/documentation/#enable. auto.commit auto commit> for the consumer.
77
91
noAutoCommit :: ConsumerProperties
78
92
noAutoCommit =
79
93
extraProps $ M. fromList [(" enable.auto.commit" , " false" )]
80
94
81
- -- | Disables auto offset store for the consumer
95
+ -- | Disable auto offset store for the consumer.
96
+ --
97
+ -- See <https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md enable.auto.offset.store> for more information.
82
98
noAutoOffsetStore :: ConsumerProperties
83
99
noAutoOffsetStore =
84
100
extraProps $ M. fromList [(" enable.auto.offset.store" , " false" )]
85
101
86
- -- | Consumer group id
102
+ -- | Set the consumer <https://kafka.apache.org/documentation/# group.id group id>.
87
103
groupId :: ConsumerGroupId -> ConsumerProperties
88
104
groupId (ConsumerGroupId cid) =
89
105
extraProps $ M. fromList [(" group.id" , cid)]
90
106
107
+ -- | Set the <https://kafka.apache.org/documentation/#client.id consumer identifier>.
91
108
clientId :: ClientId -> ConsumerProperties
92
109
clientId (ClientId cid) =
93
110
extraProps $ M. fromList [(" client.id" , cid)]
94
111
112
+ -- | Set the consumer callback.
113
+ --
114
+ -- For examples of use, see:
115
+ --
116
+ -- * 'errorCallback'
117
+ -- * 'logCallback'
118
+ -- * 'statsCallback'
95
119
setCallback :: (KafkaConf -> IO () ) -> ConsumerProperties
96
120
setCallback cb = mempty { cpCallbacks = [cb] }
97
121
98
- -- | Sets the logging level.
122
+ -- | Set the logging level.
99
123
-- Usually is used with 'debugOptions' to configure which logs are needed.
100
124
logLevel :: KafkaLogLevel -> ConsumerProperties
101
125
logLevel ll = mempty { cpLogLevel = Just ll }
102
126
103
- -- | Sets the compression codec for the consumer.
127
+ -- | Set the <https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md compression. codec> for the consumer.
104
128
compression :: KafkaCompressionCodec -> ConsumerProperties
105
129
compression c =
106
130
extraProps $ M. singleton " compression.codec" (kafkaCompressionCodecToText c)
107
131
108
- -- | Suppresses consumer disconnects logs .
132
+ -- | Suppresses consumer <https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md log.connection.close> .
109
133
--
110
134
-- It might be useful to turn this off when interacting with brokers
111
- -- with an aggressive connection.max.idle.ms value.
135
+ -- with an aggressive @ connection.max.idle.ms@ value.
112
136
suppressDisconnectLogs :: ConsumerProperties
113
137
suppressDisconnectLogs =
114
138
extraProps $ M. fromList [(" log.connection.close" , " false" )]
115
139
116
- -- | Any configuration options that are supported by /librdkafka/.
140
+ -- | Set any configuration options that are supported by /librdkafka/.
117
141
-- The full list can be found <https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md here>
118
142
extraProps :: Map Text Text -> ConsumerProperties
119
143
extraProps m = mempty { cpProps = m }
120
144
{-# INLINE extraProps #-}
121
145
122
- -- | Any configuration options that are supported by /librdkafka/.
146
+ -- | Set any configuration option that is supported by /librdkafka/.
123
147
-- The full list can be found <https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md here>
124
148
extraProp :: Text -> Text -> ConsumerProperties
125
149
extraProp k v = mempty { cpProps = M. singleton k v }
126
150
{-# INLINE extraProp #-}
127
151
128
- -- | Sets debug features for the consumer.
129
- -- Usually is used with 'consumerLogLevel '.
152
+ -- | Set <https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md debug> features for the consumer.
153
+ -- Usually is used with 'logLevel '.
130
154
debugOptions :: [KafkaDebug ] -> ConsumerProperties
131
155
debugOptions [] = extraProps M. empty
132
156
debugOptions d =
133
157
let points = Text. intercalate " ," (kafkaDebugToText <$> d)
134
158
in extraProps $ M. fromList [(" debug" , points)]
135
159
160
+ -- | Set <https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md queued.max.messages.kbytes>
136
161
queuedMaxMessagesKBytes :: Int -> ConsumerProperties
137
162
queuedMaxMessagesKBytes kBytes =
138
163
extraProp " queued.max.messages.kbytes" (Text. pack $ show kBytes)
139
164
{-# INLINE queuedMaxMessagesKBytes #-}
140
165
141
- -- | Sets the callback poll mode.
142
- --
143
- -- The default 'CallbackPollModeAsync' mode handles polling rebalance
144
- -- and keep alive events for you
145
- -- in a background thread.
146
- --
147
- -- With 'CallbacPollModeSync' the user will poll the consumer
148
- -- frequently to handle new messages as well as rebalance and keep alive events.
149
- -- 'CallbacPollModeSync' lets you can simplify
150
- -- hw-kafka-client's footprint and have full control over when polling
151
- -- happens at the cost of having to manage this yourself.
166
+ -- | Set the callback poll mode. Default value is 'CallbackPollModeAsync'.
152
167
callbackPollMode :: CallbackPollMode -> ConsumerProperties
153
168
callbackPollMode mode = mempty { cpCallbackPollMode = mode }
0 commit comments